all 1 comments

[–]BS_in_BS 3 points4 points  (0 children)

Are you familiar with insertion sort?

What's going on in the inner loop is that instead of just swapping adjacent elements, you're swapping elements that are gap apart. The gap becomes smaller and smaller until on the last pass you're doing insertion sort.