Classic sorting algorithm-comb sort comb sort
Comb sort or bubble-based sort, unlike bubbling, comb sorting compares and exchanges numbers at fixed distances, like Hill
This fixed distance is the array length divided by 1.3 to get an approximation, the next time the last obtained approximation is divided by 1.3, until the distance is small to 3 o'clock, decreasing by 1
It's not a good description, just look at the example.
Hypothetical Array [8 4 3 7 6 5 2 1]
The array length to be queued is 8, and 8÷1.3=6, then 8 and 2,4 and 1 are compared and exchanged
[8 4 3 7 6 5 2 1]
[8 4 3 7 6 5 2 1]
The result after the exchange is
[2 1 3 7 6 5 8 4]
Second cycle, update spacing for 6÷1.3=4, compare 2 and 6,1 and 5,3 and 8,7 and 4
[2 1 3 7 6 5 8 4]
[2 1 3 7 6 5 8 4]
[2 1 3 7 6 5 8 4]
[2 1 3 7 6 5 8 4]
Only 7 and 4 need to be exchanged, the result of the exchange is
[2 1 3 4 6 5 8 7]
Third cycle, update distance of 3, no swap
Fourth cycle, update distance of 2, no swap
Fifth cycle, update distance of 1, three exchange
[2 1 3 4 6 5 8 7]
[2 1 3 4 6 5 8 7]
[2 1 3 4 6 5 8 7]
The result of the three exchanges is [1 2 3 4 5 6 7 8]
Post-swap sort ends, sequential output can be obtained [1 2 3 4 5 6 7 8]
Classic sorting algorithm-comb sort comb sort