I have to write a program that implements the selection sort algorithm using recursion. I still have yet to test out my code because I'm getting errors that I don't know how to fix.
I'm using DevCpp (latest version) and I get a bunch of errors in the sort function. I copied the code to VS .NET and it compiled fine. For some reason VC .NET has linker errors with STL_ or some bull crap which is why I use DevCpp. Can anyone else compile this on devcpp? Or know why i'm getting errors?
[Warning] In function `int sort(int*, int)':
parse error before ` =' token
parse error before ` )' token
..a bunch of errors about scope and variables not being declared even though they are. Anyone know wtf is going on?
Code:#include <iostream> using namespace std; int sort(int [], int); const int MAX_ELEMENTS = 10; int main() { int unsorted[MAX_ELEMENTS] = {5,3,748,6,8,65,8,66,4,13}; sort(unsorted, 0); cout << "{ "; for (int i=0; i<=MAX_ELEMENTS; i++) cout << unsorted[i] << " "; cout << "}" << endl; } int sort(int array[], int loc) { if (loc == MAX_ELEMENTS) { return 0; } int small = array[loc]; int tmp = 0; int locsmall = 0; for (int i=loc; i<=MAX_ELEMENTS; i++) { if (array[i] < small) { small = array[i]; locsmall = i; } } tmp = array[loc]; array[loc] = small; array[locsmall] = tmp; sort(array, loc + 1); }



LinkBack URL
About LinkBacks


