);//对高子表递归排序}}/*显示顺序表*/voiddisplay(sqlist*l){inti;for(i=1;i<=l->length;i++)//输出顺序printf("%-4.2d",i);printf("\n");for(i=1;i<=2*l->length;i++)//输出分隔符printf("--");printf("\n");for(i=1;i<=l->length;i++)//输出排列好的数printf("%-4.2d",l->r[i].key);}/*调整h->r[s]的关键字,使h->r[s]成为一个大顶堆*/voidheapadjust(sqlist*h,ints,intm){keytyperc;intj;rc=h->r[s];for(j=2*s;j<=m;j*=2){if(j<m&&h->r[j].key<h->r[j+1].key)++j;if(rc.key>=h->r[j].key)break;7h->r[s]=h->r[j];s=j;}h->r[s]=rc;}/*对顺序表h进行堆排序*/voidheapsort(sqlist*h){keytyperc;inti;for(i=h->length/2;i>0;--i)heapadjust(h,i,h->length);for(i=h->length;i>1;--i){rc=h->r[1];h->r[1]=h->r[i];h->r[i]=rc;heapadjust(h,1,i-1);}}/*主函数*/voidmain(){sqlistt;creat(&t);Qsort(&t,1,t.length);printf("\n\n");printf("快速排序:\n");display(&t);heapsort(&t);printf("\n");printf("堆排序:\n");display(&t);}