#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 %d\n",x[i].name,x[i].score);
}
return 0;
}
为什么快速排列下面的代码跑不动呢,输入完就没有输出了
- 写回答
- 好问题 0 提建议
- 追加酬金
- 关注问题
- 邀请回答
-
3条回答 默认 最新
- 大太子二太子 2021-01-04 14:36关注
陷入死循环了,arr[high].score > temp.score里应该加上low<high的判断,要不然从头找到尾了
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报
悬赏问题
- ¥15 python中transformers可以正常下载,但是没有办法使用pipeline
- ¥50 分布式追踪trace异常问题
- ¥15 人在外地出差,速帮一点点
- ¥15 如何使用canvas在图片上进行如下的标注,以下代码不起作用,如何修改
- ¥15 Windows 系统cmd后提示“加载用户设置时遇到错误”
- ¥50 vue router 动态路由问题
- ¥15 关于#.net#的问题:End Function
- ¥15 无法import pycausal
- ¥15 weditor无法连接模拟器Local server not started, start with?
- ¥20 6-3 String类定义