Selection Sort.
(Yes, algorithms have names.)
Here is a description of selection sort:
Input: a list of integers
Output: the list is sorted
for each index J of the list from 0 to length-2
Find the integer that should be placed at index J.
Do this by looking for the smallest integer among those with index J or higher.
Swap that integer with the integer at J.
(Sometimes this swaps the integer at J with itself.)
Swapping integers means to exchange two integers with each other. For example, in the following list, the first move would be to swap the 17 and the 2. The other integers in the list do not need to be moved.
In the above, swap the 17 and the 2. You now have a sorted sublist of one integer.
The next move is to swap the 5 and the 4. You now have a sorted sublist of two integers.
Keep going until the list is sorted.
Why does J stop at length-2
?