快速排序的问题
这段代码在我机子上组建没有问题,可运行后的结果是什么也没有,不知道为什么,麻烦大家看看到底是哪里出问题了?
程序代码:# include <stdio.h>
void QuickSort(int *, int, int);
int FindPos(int *, int, int);
int main(void)
{
int i;
int a[8] = {2, 5, 3, 65, 43, 53, 24, 8};
QuickSort(a, 0, 7);
for (i=0; i<8; i++)
printf("%d ", a[i]);
printf("\n");
return 0;
}
void QuickSort(int * a, int low, int high)
{
int pos;
while (low < high)
{
pos = FindPos(a, low, high);
QuickSort(a, low, pos-1);
QuickSort(a, pos+1, high);
}
}
int FindPos(int * a, int low, int high)
{
int val = a[low];
while (low < high)
{
while (low<high && a[low]<=val)
low++;
while (low<high && a[high]>=val)
high--;
}
return low;
}










这个排序有点特别啊,FindPos函数可以在找到合符要求的元素后直接移动,不需要互换。