正在加载图片...
rectype r[n+d /*Rd1-]为d个监视哨 int dt /*dO到d[t-为增量序列* SHELLSORT(R, d) Rectype r: int d[: fint i,j,k,h ectype temp int maxint=32767 机器中最大整数* for(F0; K<d[0]: 1++) RI.key=-maxint 设置哨兵* K=0: H=d[k]: *取本趟增量* For(Fh+di: K<n+dl: i++) /+R[hd]到R[n+d1-1插入当前有序区* temp=R[); 保存待插入记录R]*/ while( temp. key<R[]key)/查找正确的插入位置*/ R[+h]=R[i]} /后移记录* *得到前一记录位置* RI+h=temp; /*插入R[]*/ /*本趟排序完成* k++; i while(h!=1); /*增量为1排序后终止算法* / SHELLSORT/rectype R[n+d1]; /* R[d1 -1]为d1个监视哨*/ int d[t]; /* d[0]到d[t-1]为增量序列*/ SHELLSORT(R,d) Rectype R[ ]; int d[ ]; {int i,j,k,h; rectype temp; int maxint=32767; /*机器中最大整数*/ for (i=0;i<d[0];i++) R[i].key=-maxint; /*设置哨兵*/ K=0; Do{ H=d[k]; /*取本趟增量*/ For(i=h+di;i<n+d1;i++) /*R[h+d1]到R[n+d1-1]插入当前有序区*/ {temp=R[i]}; /*保存待插入记录R[i]*/ j=i-h; while(temp.key<R[j].key) /*查找正确的插入位置*/ {R[j+h]=R[j]}; /*后移记录*/ j=j-h; /*得到前一记录位置*/ } R[j+h]=temp; /*插入R[i]*/ } /*本趟排序完成*/ k++; } while (h!=1); /*增量为1排序后终止算法*/ } /*SHELLSORT*/
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有