voidInsertSortWithGap(intarray[], int size, int gap){ for (int i = gap; i < size; i++) { int key = array[i]; int j; for (j = i - gap; j >= 0 && array[j] > key; j -= gap) { array[j + gap] = array[j]; } array[j + gap] = key; } }
voidShellSort(intarray[], int size){ int gap = size; while (1) { // 原始增量序列 gap /= 2; // gap = gap / 3 + 1; InsertSortWithGap(array, size, gap); if (gap == 1) { break; } } }