c - 函数不能返回值

标签 c function quicksort

我正在用 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/

相关文章:

c - C语言中如何将两个字符串的字符随机组合在一起?

更改函数内的指针

c++ - 不能将 vector 作为参数传递 c++

c - 用C语言编写的快速排序

python - 类型错误 : unsupported operand type(s) for -: 'str' and 'int' (Python)

algorithm - 为什么 QuickSort Single pivot 比 3-way partition 更快?

c - 重新分配错误: realloc(): invalid next size

c - 为什么 scanf 不接受元素进入这个 C 结构?

C - Malloc 问题(也许是别的)

c++ - 我的电脑不接受 s.length,但其他编译器接受