31 #ifndef ACE_SORTING_SHELL_SORT_H
32 #define ACE_SORTING_SHELL_SORT_H
36 namespace ace_sorting {
52 for (uint16_t i = gap; i < n; i++) {
57 for (j = i; j >= gap; j -= gap) {
58 if (data[j - gap] <= temp)
break;
59 data[j] = data[j - gap];
90 for (uint16_t i = gap; i < n; i++) {
95 for (j = i; j >= gap; j -= gap) {
96 if (data[j - gap] <= temp)
break;
97 data[j] = data[j - gap];
124 static const uint16_t sGaps[] = {
125 1, 4, 9, 20, 46, 103, 233, 525, 1182, 2660, 5985, 13467, 30301,
127 const uint16_t nGaps =
sizeof(sGaps) /
sizeof(uint16_t);
131 for (iGap = 0; sGaps[iGap] < n && iGap < nGaps; iGap++) {}
132 if (iGap != 0) iGap--;
135 uint16_t gap = sGaps[iGap];
138 for (uint16_t i = gap; i < n; i++) {
143 for (j = i; j >= gap; j -= gap) {
144 if (data[j - gap] <= temp)
break;
145 data[j] = data[j - gap];
155 if (iGap == 0)
break;