c++ - 错误 : Control reaches end of non-void function in C++ for selection sort function

标签 c++ function selection-sort

对于此作业,我必须在另一个文件中编写一个选择排序函数,该函数按升序对数组进行排序,以便在我的驱动程序中使用。我已经在这个问题中搜索了我的错误,但我仍然没有找到任何我见过的可以帮助我的东西。有人可以帮帮我吗?

这是我目前所拥有的。

#include <iostream>
using namespace std;


void *selectionsort(int values[], int size){


    for(int i=0; i<size-1; i++){
        for(int j=0; j<size; j++){
            if(values[i] < values[j]){
                int temp = values[i];
                values[i] = values[j];
                values[j] = temp;


            }

        }

    }
}

如果需要的话,这是我的司机。

#include <stdlib.h>
#include <iostream>
#include "selection.cpp"

using namespace std;

#define ArraySize 10 //size of the array
#define  Seed  1 //seed used to generate random number

int values[ArraySize];


int main(){


    int i;

    //seed random number generator
    srand(Seed);

    //Fill array with random intergers
    for(i=0;i<ArraySize;i++)
        values[i] = rand();

    cout << "\n Array before sort" << endl;

    for(i=0;i<ArraySize; i++)
        cout << &values[]<< "\n";

    //int* array_p = values;

    cout << "\n Array after selection sort." << endl;

    //Function call for selection sort in ascending order.
    void *selectionsort(int values[], int size);

    for (i=0;i<ArraySize; i++)
        cout << &values[] << "\n";


    //system("pause");

}

最佳答案

你的函数不是无效的,把它改成

void selectionsort(int values[], int size){

额外:如果您这样定义函数,它会返回一个空指针。 void 指针是可以指向……任何东西的指针。

当然,请参阅@brokenfoot 的回答以了解如何调用函数。

关于c++ - 错误 : Control reaches end of non-void function in C++ for selection sort function,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22369266/

相关文章:

c++ - 如何比较 time_t 和 std::filesystem::file_time_type

c++ - 多线程:我需要用只读方法保护我的变量吗?

c++ - 如何强制 g++ 链接器加载不直接调用的符号 - 避免 undefined reference

python - matplotlib 中的条件函数绘图

python - 在 python 中使用选择排序对数组进行排序。我该如何优化?

c - c中链表的选择排序

c++ - 为什么人们使用 Type *var 而不是 Type* var?

javascript - 从函数 jquery 内的函数获取值

R类型转换expression()function()

c - 如何在 C 语言的选择排序中打印每次迭代?