Descending Selection Sort function
Feb 6, 2018 at 10:02pm UTC
Hello, again. I am having some difficulties changing this selectionsort function from ascending to descending. Any help with this would great!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
void sortScores(int arr[],int size)
{
int startScan, minIndex, minValue;
for (startScan = 0; startScan<(size - 1); startScan++)
{
minIndex = startScan;
minValue = arr[startScan];
for (int index = startScan + 1; index < size; index++)
{
if (arr[index] < minValue)
{
minValue = arr[index];
minIndex = index;
}
}
arr[minIndex] = arr[startScan];
arr[startScan] = minValue;
}
}
Feb 6, 2018 at 10:50pm UTC
There is a single expression here that is dependent on the order of the values in the sequence you are sorting. I imagine if you changed that expression to the "opposite" of what it is, you'd reverse the sorted sequence.
Feb 7, 2018 at 12:19am UTC
I could have sworn I tried that first LOL. It worked!!! thanks so much.
I have another question, hopefully you can help me.
How do I get the sorted scores to show up on a numbered list:
example:
Top Scores:
1.
2.
3.
4.
5.
Topic archived. No new replies allowed.