2014-03-13 42 views
0

对于这个任务,我有在升序排序列在我的司机使用另一个文件中写入选择排序功能的结束。我已经为这个错误搜索了这个问题,而且我还没有发现任何我见过的可以帮助我。有人可以帮我吗?错误:控制达到C非void函数++的选择排序功能

这是我到目前为止。

#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"); 

} 
+0

这是不是你调用一个函数...摔落'无效*'。另外为什么是void函数的指针? – smac89

回答

2

你的函数是不是无效改变

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

额外:如果你这样定义它,你的函数返回一个void指针。而一个void指针是一个指针,可以指向...以及任何东西。

当然,看看@ brokenfoot的回答,以了解如何调用一个函数。

+0

非常感谢你!!!! – ML45

0
  1. 既然你定义了你的main()作为int main()意味着它返回一个int。所以,在你的主尾架前,加return 0;
  2. ,因为你不是从selectionsort()函数返回时,使其无效:
    void selectionsort(int values[], int size)
  3. 当你调用在main(此功能),这样称呼它:
    selectionsort(values,size);
+0

注1:如果省略的主要功能return语句大多数编译器不会抱怨,即使它被声明为INT的main(),但它始终是一个很好的做法,添加它的原因有很多... –

+1

是啊, OP请记下它。对于C来说它并不重要,但对于C++来说是必需的。 http://stackoverflow.com/questions/204476/what-should-main-return-in-c-and-c – brokenfoot

相关问题