I managed to fix the problem, it wasn't in that function but in my other function. I was storing it twice. By the way, our instructor wants us to use this type of sorting. Thank you for your reply.
I do however have another issue. Within that selectSort function I am also calling my second array that has stored in it, the string value of the class level. For example:
Credits Completed Class Level
Under 32 Freshman
32 – 63 Sophomore
64 - 95 Junior
Over 95 Senior
The following text file has:
DD444444 U 52
CD334455 U 100
DD444444 has 52 completed credits so class level is Sophomore
Also the ordinal value of FRESHMAN will be 0, and the ordinal value of SENIOR will be 3. So in my classLevel[] array I have the string value stored in it; ie, Senior, etc.
Problem:
When I use this same function to sort classLevel[], it sorts it in this manner:
Sophomore, Senior, Junior, and Freshman. Not in the order of the text file. For example, if CD334455 was in array[1] than the corresponding 100 or Senior should aslo be in array[1].
Here is my code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
|
void selectSort(string array[], int& cnt)
{
int curTop, // Current top of unsorted list
next, // Position to compare value to
max; // Position of greatest value
string temp; // Temp value for swapping
// for each item in the list (top to bottom)
for (curTop = 0; curTop < cnt - 1; curTop++)
{
max = curTop; // start with current top as greatest value
// find greatest value from curTop down
for (next = curTop + 1; next < cnt; next++)
if (array[next] > array[max])
{
max = next;
array[max] = array[next];
}
//if greatest not at curTop, swap with curTop
if (max != curTop)
{
temp = array[curTop];
array[curTop] = array[max];
array[max] = temp;
} // end swap
}
return;
}
|
Any help would be appreciated. thank you.