排序算法四:希尔排序
#include <stdio.h> //希尔排序就是插入排序的非递增1版本,插入排序每次递增1,希尔排序递增incream,将incream换为1,会发现,跟插入排序代码基本一致。 void ShelltSort(int *L) { int i, j, incream; incream = 10; do { incream = incream / 3 + 1; for (i = incream + 1; i <= 10; i++) { if (L[i] < L[i - incream]) { L[0] = L[i]; for (j = i - incream; j > 0 && L[j] > L[0]; j -= incream) { L[j + incream] = L[j]; } L[j + incream] = L[0]; } } } while (incream > 1); } int main() { int L[11] = { -1,3,2,5,6,8,1,9,4,7,0 }; int i = 1; for (; i <= 10; i++) { printf("%d ", L[i]); } printf("\n"); ShelltSort(L); for (i = 1; i <= 10; i++) { printf("%d ", L[i]); } printf("\n"); return 0; }