Reputation: 47
For this assignment I have to write a selection-sort function in another file that sorts arrays in ascending order to use in my driver. I've already searched this question for my error and I still haven't found anything that I've seen can help me out. Can someone please help me out?
Here's what I have so far.
#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;
}
}
}
}
Here's my driver if needed.
#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");
}
Upvotes: 0
Views: 264
Reputation: 11649
int main()
means it returns an int. SO, before your end bracket in main, add a return 0;
selectionsort()
function, make it void:void selectionsort(int values[], int size)
selectionsort(values,size);
Upvotes: 0
Reputation: 595
Your function is not void change it to
void selectionsort(int values[], int size){
Extra: Your function returns a void pointer, if you define it like that. And a void pointer is a pointer that can point to... well anything.
And of course see @brokenfoot's answer to learn how to call a function.
Upvotes: 2