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

到目前为止,这就是我所拥有的。

#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){


附加:如果您这样定义函数,则该函数将返回一个空指针。无效指针是可以指向...以及任何东西的指针。

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

关于c++ - 错误:控件到达C++中用于选择排序功能的非空函数的结尾,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/22369266/

10-11 23:15
查看更多