1、算法原理
算法演示
2、程序代码
#include#define MAX 255int R[MAX];void ShellPass(int d,int n){/*希尔排序中的一趟排序,d为当前增量*/ int i,j; for(i=d+1;i<=n;i++) { if(R[i] 0&&R[0] 0*/ do { increment=increment/3+1;/*求下一增量*/ ShellPass(increment,n);/*一躺增量为increment的shell插入排序*/ }while(increment>1);}int main(){ int i,n; printf("Please input total element number of the sequence:"); scanf("%d",&n); if(n<=0||n>MAX) { printf("n must more than o and less than %d.\n",MAX); exit(0); } printf("Please input the elements one by one:"); for(i=1;i<=n;i++) { scanf("%d",&R[i]); } printf("The sequence you input is:"); for(i=1;i<=n;i++) { printf("%4d",R[i]); } Shell_Sort(n); printf("\n The sequence after shell_sort is:"); for(i=1;i<=n;i++) { printf("%4d",R[i]); } printf("\n Press any key to quit..."); getchar(); return 0;}