麻烦各位C语言高手看错

来源:百度知道 编辑:UC知道 时间:2024/05/04 15:15:39
#include<stdio.h>//快速排序
void qSort(int *p,int *q);
int *partition(int *p,int *q);
void swap(int *a, int *b);
void main()
{
int i,*low,*high,a[10];
printf("请输入10个数组元素:\n");
for(i=0;i<10;i++) scanf("%d",&a[i]);
low=a;
high=a+9;
qSort(low,high);
for(i=0;i<10;i++) printf("%d ",a[i]);
printf("\n");
}
int *partition(int *p,int *q)
{
int *key=p;
q=p+9;
while(p<q)
{
while(p<q&&*q>=*key) --q;
swap(p,q);
while(p<q&&*p<=*key) ++p;
swap(p,q);
}
return p;
}
void qSort(int *p,int *q)
{
int *key;
if(p<q)
{
key=partition(p,q);
qSort(p,key-1);
qSort(key+1,q);
}
}
void swap(int *a, int *b)
{
int temp;
temp=*a;
*a=*b;
*b=temp;
}
把 q=p+9 去掉 结果还是不对
刚才那个问题我关闭了

int *partition(int *p,int *q)
{
int *key=p;
q=p+9;
while(p<q)
{
while(p<q&&*q>=*key) --q;
swap(p,q);
while(p<q&&*p<=*key) ++p;
swap(p,q);
}
把q=p+9;去掉就可以了
顺便问下,你刚才提的那个问题哪去了?
我进去回答的时候说该问题不存在!