标题:快速排序
只看楼主
yzhw29
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2007-10-8
 问题点数:0 回复次数:0 
快速排序

/* bo10-2.c 快速排序的函数 */
void QSort(SqList *L,int low,int high)
{ /* 对顺序表L中的子序列L.r[low..high]作快速排序。算法10.7 */
int pivotloc;
if(low<high)
{ /* 长度大于1 */
pivotloc=Partition(L,low,high); /* 将L.r[low..high]一分为二 */
QSort(L,low,pivotloc-1); /* 对低子表递归排序,pivotloc是枢轴位置 */
QSort(L,pivotloc+1,high); /* 对高子表递归排序 */
}
}

void QuickSort(SqList *L)
{ /* 对顺序表L作快速排序。算法10.8 */
QSort(L,1,(*L).length);
}

void print(SqList L)
{
int i;
for(i=1;i<=L.length;i++)
printf("(%d,%d)",L.r[i].key,L.r[i].otherinfo);
printf("\n");
}

2007-10-09 07:42



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-176002-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 2.165198 second(s), 9 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved