The time complexity of hill sorting is between O (N) and O (n2), and the practical performance in sorting large amounts of data exceeds that of heap sorting. Features:AlgorithmSimple but complex analysis. The following is an implementation:
/** A [] is an array to be sorted * N1 is the T array length * Inc [] is the array to indecate the increasement * N2 is the INC array length */template <typename T> void shellsort (t a [], int N1, int Inc [], int N2) {for (INT I = 0; I <N2; ++ I) {for (Int J = inc [I]; j <N1; ++ J) {t tmp = A [J]; int K; For (k = J; k> = inc [I]; k-= inc [I]) {If (TMP <A [k-Inc [I]) A [k] = A [k-Inc [I]; elsebreak;} A [k] = TMP ;}}}
Notes:
1. Refer to the descending sequence for hill sorting. The 2k-1 (value <n) sequence can be used. Sedgewick sequence is used for large data volumes.
2. Sorting at each interval is actually an insert sorting instead of a Bubble sorting. So we need to traverse from the back to the front.