You have too many swaps for a selection sort. You should have at most one swap for every trip through the outer loop, so you should not have a swap inside the INNER loop. The algorithm, from Wikipedia.

Find the minimum value in the list

Swap it with the value in the first position

Repeat the steps above for the remainder of the list (starting at the second position and advancing each time)

You don't know the answer to step 1 until after the inner loop has completed. Therefore step 2 should not occur until after the the inner loop has completed.

line 8 should have test index < length-1 As VernonDozier mentioned, the proper version of this has the swap after the inner loop has found the one and only smallest remaining item. Doing the swaps inside the inner loop should still give correct result, but it will make the runtime pretty much equal to that of Bubble sort, if not a bit worse.

What's happening is that you are making an incorrect comparison after the first swap. smallestIndex initially point to the place you want to fill, but you change it to point to where you've found the smallest currently seen value. Your further comparisons are then looking at a spot in the unsorted portion instead of at the known smallest value.