|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
没有输出,好奇怪,麻烦鱼油们看一下吧#include<stdio.h>
void supersort(int a[],int left,int right)
{
int i = left,j = right,middle = (i+j)/2;
int flag = a[middle],temp;
while(i<=j)
{
while(a[i] <= flag)
{
i++;
}
while(a[j] >= flag)
{
j++;
}
if(i<=j)
{
temp = a[i];
a[i] = a[j];
a[j] = temp;
i++;
j--;
}
}
if(left < j)
supersort(a,left,j);
if(right > i)
supersort(a,i,right);
}
int main()
{
int a[10]={91,95,102,100,144,155,454,231,45,1},length,i=0;
length = 10;
supersort(a,0,length-1);
for(;i<10;i++)
printf("%4d",a[i]);
return 0;
}
本帖最后由 jhanker 于 2020-7-3 17:14 编辑 #include<stdio.h>
void supersort(int a[],int left,int right)
{
if(left< right){
int i = left,j= left,middle = (i+j)/2;
int flag = a[middle],temp;
temp=a[middle];
a[middle]=a[right];
a[right]=temp;
for( ; j < right ; ++j){
if(a[j] <= flag){
temp=a[j];
a[j]=a[i];
a[i]=temp;
i++;
}
}
temp=a[i];
a[i]=a[right];
a[right]=temp;
supersort(a,left,i-1);
supersort(a,i+1,right);
}
}
int main()
{
int a[10]={91,95,102,100,144,155,454,231,45,1},length,i=0;
length = 10;
supersort(a,0,length-1);
for(;i<10;i++)
printf("%4d",a[i]);
return 0;
}
|
|