The sorting algorithm might not necessarily place items in their correct position after each comparison. For example, your array is less than 20 elements, so the stdlib will use an insertion sort algorithm to sort your array. Using a modified version of the stdlib code to print out the state of the array will produce the following results:
Array states after swaps
(note I used the same array as you except that I moved 1
to a the 5th position to show how long it takes to get into it's correct position)
[10, 10, 6, 20, 1, 45, 3, 12, 14, 21, 6, 7]
[5, 10, 10, 20, 1, 45, 3, 12, 14, 21, 6, 7]
[5, 6, 10, 20, 20, 45, 3, 12, 14, 21, 6, 7]
[5, 6, 10, 10, 20, 45, 3, 12, 14, 21, 6, 7]
[5, 6, 6, 10, 20, 45, 3, 12, 14, 21, 6, 7]
[5, 5, 6, 10, 20, 45, 3, 12, 14, 21, 6, 7]
[1, 5, 6, 10, 20, 45, 45, 12, 14, 21, 6, 7]
[1, 5, 6, 10, 20, 20, 45, 12, 14, 21, 6, 7]
[1, 5, 6, 10, 10, 20, 45, 12, 14, 21, 6, 7]
[1, 5, 6, 6, 10, 20, 45, 12, 14, 21, 6, 7]
[1, 5, 5, 6, 10, 20, 45, 12, 14, 21, 6, 7]
[1, 3, 5, 6, 10, 20, 45, 45, 14, 21, 6, 7]
[1, 3, 5, 6, 10, 20, 20, 45, 14, 21, 6, 7]
[1, 3, 5, 6, 10, 12, 20, 45, 45, 21, 6, 7]
[1, 3, 5, 6, 10, 12, 20, 20, 45, 21, 6, 7]
[1, 3, 5, 6, 10, 12, 14, 20, 45, 45, 6, 7]
[1, 3, 5, 6, 10, 12, 14, 20, 21, 45, 45, 7]
[1, 3, 5, 6, 10, 12, 14, 20, 21, 21, 45, 7]
[1, 3, 5, 6, 10, 12, 14, 20, 20, 21, 45, 7]
[1, 3, 5, 6, 10, 12, 14, 14, 20, 21, 45, 7]
[1, 3, 5, 6, 10, 12, 12, 14, 20, 21, 45, 7]
[1, 3, 5, 6, 10, 10, 12, 14, 20, 21, 45, 7]
[1, 3, 5, 6, 6, 10, 12, 14, 20, 21, 45, 45]
[1, 3, 5, 6, 6, 10, 12, 14, 20, 21, 21, 45]
[1, 3, 5, 6, 6, 10, 12, 14, 20, 20, 21, 45]
[1, 3, 5, 6, 6, 10, 12, 14, 14, 20, 21, 45]
[1, 3, 5, 6, 6, 10, 12, 12, 14, 20, 21, 45]
[1, 3, 5, 6, 6, 10, 10, 12, 14, 20, 21, 45]
[1, 3, 5, 6, 6, 7, 10, 12, 14, 20, 21, 45]
Basically, you can't really know whether the item in the first position (any position) is correct until you completely sort the array.