The Interchange Sort

The interchange sort orders a list alphabetically or in order of size by picking the first in order, wherever it is in the list, and swapping that with the first element in the unsorted list, if necessary. The second in order is swapped with the second in the list, the third with the third in the list and so on. The process is repeated until the list is sorted.

For example, to sort the list

4, 2, 5, 8, 1, 7, 9

The smallest number in the list is 1 so this is swapped with the first number to give the list

1, 2, 5, 8, 4, 7, 9

The next smallest number in the list is 2 and this is second so does not need to be swapped

1, 2, 5, 8, 4, 7, 9

The next smallest number in the list is 4 so this is swapped with the third number to give the list

1, 2, 4, 8, 5, 7, 9

The next smallest number in the list is 5 so this is swapped with the fourth number to give the list

1, 2, 4, 5, 8, 7, 9

The next smallest number in the list is 7 and this is sixth so does not need to be swapped

1, 2, 5, 8, 4, 7, 9

The next smallest, and last number in the list is 9 and this is sixth so does not need to be swapped

1, 2, 5, 8, 4, 7, 9

The list is sorted