Admirable, but your algorithm is wrong, or at least not selection sort. Notice that when you find an element smaller than the currently known smallest, you swap it with the current element. However, you then set smallest to the index of the currently known smallest... but wait, the currently known smallest has been swapped, so smallest is now the index of the current element, and in fact current is the index of the currently known smallest.Originally Posted by AndrewHunter
If you wanted to avoid a swap if none is required, swap if smallest != current.