Can the BubbleSort be changed so it sorts from high to low? What do you need to change in the code to make this happen?
What will be an ideal response?
Yes, it can be changed to sort from high to low. The comparison statement in the nested for loop is where the low to high/high to low order is established.
If the comparison is if( numbers[j-1] > numbers[j] ) this swaps higher values down in the array, so it is ordered low to high.
If the comparison is if( numbers[j-1] < numbers [j] ) this swaps lower values down in the array, so it is ordered high to low. You only need to switch the < and > to change the resultant sort order in the array.
You might also like to view...
A function __________ specifies the return data type, name of the function, and the parameter variable(s).
a. definition b. body c. header d. statement
Explain why a read-only transaction consisting of a single SELECT statement that uses an INSENSITIVE cursor can always execute correctly at READ COMMITTED.
What will be an ideal response?