c++ - Sorting names alphabetically using selection sort. -
okay, posted same question earlier , got on arrays/vectors , on. fixed people told me run issues program gives me bunch of errors. , time, don't see wrong. makes perfect sense me doesn't computer , i'm mere novice.
so here's i'm trying accomplish. reading names file called names.dat , has names saved this:
collins, bill\n smith, bart\n allen, jim\n . . . holland, beth
i'm trying sort these names alphabetically (both ascending , descending order). let alone descending order now, wrote program supposed sort these names in ascending order. keeps spitting out errors don't understand meanings of. don't know if errors coming deque , string i'm trying define, or other parts. here's got far.
#include<iostream> #include<fstream> #include<iomanip> #include<deque> using namespace std; const int size = 20; void setascendingsort(string [], int); void displayarray(string [], int); int main() { deque<string> names; ifstream infile; infile.open("names.dat"); string name; while(getline(infile, name)) { names.push_back(name); } cout << "the values before selection sort performed are:" << endl; displayarray(names, size); setascendingsort(names, size); cout << "the values after selection sort performed are:" << endl; displayarray(names, size); return 0; } void displayarray(string array[], int elems) { for(int count = 0; count < elems; count++) cout << array[count] << " "; cout << endl; } void setascendingsort(string array[], int elems) { int seek = 0; int mincount; int minvalue; (seek = 0; seek < (elems - 1); seek++) { mincount = seek; minvalue = array[seek]; (int index = seek + 1; index < elems; index++) { if (array[index] < minvalue) { minvalue = array[index]; mincount = index; } } array[mincount] = array[seek]; array[seek] = minvalue; } }
what kind of mistakes see don't see? i'm beginner programming , appreciate sort of help. in advance!
Comments
Post a Comment