gpt4 book ai didi

代码只接受输入值然后什么也不会发生

转载 作者:行者123 更新时间:2023-11-30 16:11:48 25 4
gpt4 key购买 nike

这个快速排序程序在运行时获取输入值,然后什么也没有发生既没有程序终止,也没有显示输出。

我检查了算法两次,但找不到任何解决方案。

#include<stdio.h>
void quicksort(int a[25],int beg,int end)
{
int loc, right, left, temp;

if(beg<end)
{
left=beg;
loc=beg;
right=end;

while(loc<right)
a[loc]=a[right];
a[right]=temp;
}
{


while(a[loc]<=a[left]&&loc<end)
loc++;
while(a[right]>a[left])
right--;
if(loc<right)
{
temp=a[loc];
}

temp=a[left];
a[left]=a[right];
a[right]=temp;
quicksort(a,beg,right-1);
quicksort(a,right+1,end);

}
}

int main()
{
int i,n, a[25];
printf("Enter the no of elements:");
scanf("%d",&n);
printf("Enter the array elements:");
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
quicksort(a,0,n-1);

printf("Elements after sorting is:");
for(i=0;i<n;i++)
printf(" %d",a[i]);


return 0;
}

未显示输出。提供输入后,光标卡住在一处

最佳答案

这会永远循环:

while(loc<right)
a[loc]=a[right];

您应该修复括号的位置,也许到处添加一些。

关于代码只接受输入值然后什么也不会发生,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58496050/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com