#define MAXSIZE 10
typedef struct
{
int r[MAXSIZE];
int length;
}Sqlist;
void Swap(Sqlist *L,int i,int j)
{
int temp =L->r[i];
L->r[i] =L->r[j];
L->r[j] =temp;
}
void print(SqList L)
{
int i;
for(i=1;i<L.length;i++)
printf("%d,",L.r[i]);
printf("%d",L.r[i]);
printf("\n");
}
int Part(Sqlist *L,int low,int high)
{
int pivotkey;
pivotkey=L->r[low];
while(low < high)
{
while(low < high && pivotkey <= L->r[high])
high--;
Swap(L,low,high);
while(low < high && pivotkey >=L->r[low])
low++;
Swap(L,low,high);
}
return low;
}
void Qsort(Sqlist *L,int low,int high)
{
int pivot;
if(low < high)
{
pivot=Part(L,low,high);
Qsort(L,low,pivot-1);
Qsort(L,pivot+1,high);
}
}
void QuickSort(SqList *L)
{
Qsort(L,1,L->length);
}
快速排序
最新推荐文章于 2021-11-19 16:57:43 发布