这段快速排序代码有什么问题,为什么得不到结果

[复制链接]
查看11 | 回复1 | 2011-6-7 12:19:52 | 显示全部楼层 |阅读模式
#include
int quicksort(int a[],int low,int high)
{
        a[0]=a[high];
        while(low=a[0])
                         high--;
                a[low]=a[high];
        }
        a[low]=a[0];
        return low;
}
void sort(int a[],int low,int high)
{
        int t;
        while(low<high){
         t=quicksort(a,low,high);
         sort(a,low,t-1);
         sort(a,t+1,high);
        }
}
main()
{
        int i,a[11];

for(i=1;i<=10;i++)
        {
                printf("Enter a[%d]=",i);
                scanf("%d",&a);
        }
        printf("before sort:");
        for(i=1;i<=10;i++)
        {
                printf("%d ",a);
        }
        sort(a,1,10);

printf("after sort:");
        for(i=1;i<=10;i++)
        {
                printf("%d ",a);
        }
}
其中a[0]作为辅助量,对a[1]-a[10]进行快速排序

回复

使用道具 举报

千问 | 2011-6-7 12:19:52 | 显示全部楼层
void sort(int a[],int low,int high){int t;while(low<high){
//这里应该改为if(low<high) t=quicksort(a,low,high); sort(a,low,t-1); sort(a,t+1,high);}}程序在c-free下测试通过。...
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行