gpt4 book ai didi

c - 函数不能返回值

转载 作者:太空宇宙 更新时间:2023-11-04 05:04:21 24 4
gpt4 key购买 nike

我正在用 C 编写快速排序排列函数的代码,但在该函数的递归调用中显示以下错误:Arrange(int,int) 无法返回值。

void Arrange(int left,int right){ 
int i,j,x,w;
i=left,j=right;
x=(left+right)/2;
do{
while(struct[i].number < struct[x].number)i++;
while(struct[j].number > struct[x].number)j--;
if(i<=j){
w=struct[i].number;
struct[i].number=struct[j].number;
struct[j].number=w;
i++;j--;
}}while(i<=j);
if(left<j)
return Arrange(left,j); //1st recursive call. It doesn't work.
if(right>i)
return Arrange(i,right); //2nd recursive call.It doesn't work either.
};

为什么会这样?

这只是一个更大程序的函数,我没有发布它,因为它看起来更像是函数的逻辑问题。它已经在完整程序中定义的结构。

最佳答案

您的函数被声明为返回 void。这使您的 return 关键字变得多余。只需删除它们即可。

关于c - 函数不能返回值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17801793/

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