void shellSort( int array[], int length) { int i; int j; int k; int gap; // gap is the step size of the grouping int temp; // Hill sorting is implemented on the basis of direct insertion sorting, so the sentinel for (gap=length/ 2 is still needed ; gap> 0 ; gap=gap/ 2 ){ for (i= 0 ; i<gap; i++ ){ for (j=i+gap; j<length; j=j+gap){ // Single insertion sort if (array[j] < array[j - gap]){ temp = array[j]; //哨兵 k = j - gap; while(k>=0 && array[k]>temp){ array[k + gap] = array[k]; k = k - gap; } array[k + gap] = temp; } } } } }