Situation: A number of students are standing in a queue.
Task: We wish to shuffle these students so that at the end, the queue is sorted by height, with the shortest student occupying first position while the tallest one occupying the last position.
Algorithm: Compare the height of student standing at first position with everyone else and swap the positions of two if they are standing in undesired order of height. This will ensure that shortest student occupies first position in the queue. Now compare the height of student standing at second position with everyone behind him and swap the positions of two if they are standing in undesired order of height. Keep doing this, starting third, fourth, fifth,...., (n-1)st student. Eventually the queue will be sorted in the desired order.
Convert this code into Python and share.
It will be great if students can share other algorithms to accomplish the task of sorting.
Keep Pythoning!