关于一个快速排序的问题
# include <stdio.h># include <malloc.h>
void Quicksort(int * a, int low, int high);
int FindPos(int * a, int loe, int high);
int main()
{
int i;
int len;
int *a;
printf("输入需要排序的个数:");
scanf("%d",&len);
a = (int *)malloc(sizeof(int)*len);
for (i = 0; i < len; i++)
{
scanf("%d",&a[i]);
}
Quicksort(a , 0, len-1);/* 0 表示第一个元素的下标, len-1 表示最后一个元素的下标*/
for (i = 0; i < len; i++)
printf("%d ", a[i]);
puts("\n");
return 0;
}
void Quicksort(int * a, int low, int high)
{
int pos;
if (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[high] >= val)
--high;
a[low] = a[high];
while (low < high && a[high] <= val)
low++;
a[high] = a[low];
}/*终止 while 循环之后, low 和 high 是相等的*/
a[low] = val;
return high; /* high 可以改成 low, 但不能改成 val, a[low], a[high]*/
}
求大神帮助下