希尔排序是是跨组的插入排序
#include<stdio.h> void SHELL_SORT(int*L,int n) { int i,j,key; int increase=n; do { increase=increase/3+1; i=increase; while(i<n) { key=L[i]; j=i-increase; while(j>=0&&L[j]>key) { L[j+increase]=L[j]; j-=increase; } L[j+increase]=key; i++; } }while(increase>1); } int main() { int test=30; int array[test]; int i=0; while(i<test) { array[i]=random()%(test*100); i++; } SHELL_SORT(array,test); i=0; while(i<test) { printf("%d\n",array[i]); i++; } return 0; }
浙公网安备 33010602011771号