Hello,
I need to complete a selection sort (descending order) on a string that contains 3 letters and one number. This is the function I wrote so far, but it doesn't sort properly. It is sorting, but I can't figure out its scheme. Any tips? Thanks! (The arrays are parallel. I just have to sort the id[] array and keep the gpa[]array connected to the right id.)
void Sort_Arrays(string id[], float gpa[], int listSize)
{
int index, // location of last index that has been sorted
largestIndex = 0, // location of largest index in unsorted portion
maxIndex = 0; // max index from entire list, moved to top position
string temp1;
float temp2;
for (index = 0; index < listSize - 1; index++)
{
largestIndex = index; // assuming 1st index is largest
for (maxIndex = index + 1; maxIndex < listSize; maxIndex++)
{
if (id[maxIndex] > id[largestIndex])
largestIndex = maxIndex;
}
temp1 = id[largestIndex];
temp2 = gpa[largestIndex];
id[largestIndex] = id[maxIndex];
gpa[largestIndex] = gpa[maxIndex];
id[maxIndex] = temp1;
gpa[maxIndex] = temp2;
}
}