Originally Posted by
iMalc
Your original post has a buffer overrun. j<5 should be j<LEN-1.
The easiest way to see if you have the boundary conditions correct is to see what happens if there are exactly two items. There should be only one compare, and if they were out of order then one swap.
If you include the change I just mentioned above, then the original code will do exactly that. However, your i>1 idea would instead mean that zero comparisons are made and it would fail to sort.
Therefore the outer loop is correct as-is; your friend was right, and you were wrong. But you both fail on missing the buffer overrun.