主题:[讨论]不知这个快排算法怎么错了?
#include<stdio.h>
#include<stdlib.h>
void qsort1(int *,int,int );
int part(int *,int,int);
int main()
{
int a[6]={5,4,6,8,4,7};
qsort1(a,0,5);
printf("%d%d%d%d%d%d",a[0],a[1],a[2],a[3],a[4],a[5]);
return 0;
}
void qsort1(int *p,int low,int high)
{
int pre;
pre=part(p,low,high);
qsort1(p,low,pre-1);
qsort1(p,pre+1,high);
}
int part(int *q,int low1,int high1)
{
int key,r;
[color=FF0000]r=*(q+low1);[/color] key=*(q+low1);
while(low1<high1)
{
while(low1<high1&&*(q+high1)>=key)
high1--;
*(q+low1)=*(q+high1);
while(low1<high1&&*(q+low1)<=key)
low1++;
*(q+high1)=*(q+low1); }
*(q+low1)=r;
return low1;
}
运行时说r=*(q+low1)这句段异常,实在不知道怎么回事...请各位帮忙指教!