Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
3.6k views
in Technique[技术] by (71.8m points)

为什么快速排列下面的代码跑不动呢,输入完就没有输出了?

为什么快速排列下面的代码跑不动呢,输入完就没有输出了



#include<stdio.h>

#include<string.h>

struct info

{

    char name[100];

    int score;

};

struct info temp;

struct info x[10];

int Qksort(struct info arr[],int low,int high)

{

    int max = high;

    int min = low;

    int flag = 0;

    temp = arr[low];

    while(low<high)

    {

        while(arr[high].score > temp.score )

            high--;

        arr[low] = arr[high];

        while (arr[low].score < temp.score)

            low++;

        arr[high] = arr[low];

        flag++;

    }

    if(flag != 0)

    {    

        arr[low] = arr[high] = temp;

        Qksort(arr,min,high);

        Qksort(arr,high+1,max);    

    }

}

int main()

{

    int m = 10;

    int i,j;

      for (i=0; i<m; i++)

      {

          printf("输入第%d个学生的信息:",i+1);

         scanf("%s %d",x[i].name,&x[i].score);

     }

      Qksort(x,0,9);

    printf("使用快速排序对上面数据按成绩非递减排列:n");

    for (i=0; i<m; i++)

    {

        printf("%s %dn",x[i].name,x[i].score);

    }

      return 0;

}










与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

代码有错吧?比如
[2,2]
这种数据就没法排序


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...