#include<stdio.h>
int a[20]={-1,2,0,7,3,12,65,78,23,43,56,32,87,54,99,100,2,48,68,54};
void display(int a[],int n);
void Shell_Sprt(int a[],int n);
int main(){
display(a,19);
Shell_Sprt(a,19);
display(a,19);
return 0;
}
void display(int a[],int n){
for(int i=1;i<=n;i++)printf("%d\t",a[i]);
printf("\n");
}
void Shell_Sprt(int a[],int n){
int d,i,j;
for(d=n/2;d>=1;d=d/2){
for(i=d+1;i<=n;++i){
if(a[i]<a[i-d]){
a[0]=a[i]; //元素从1开始存放,下标0并不是哨兵
for(j=i-d;j>0&&a[0]<a[j];j-=d){
a[j+d]=a[j];
}
a[j+d]=a[0];
}
}
}
}
运行结果