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...
What are some of the attacks on Wi-Fi?
What will be an ideal response?
You convert a label into a hyperlink label by modifying the label's Hyperlink _____ property.
Fill in the blank(s) with the appropriate word(s).
A switch is a network device that operates at Layer 2 of the OSI model.
a. true b. false
Worksheet _________________________ typically contain items analogous to items in a list.
Fill in the blank(s) with the appropriate word(s).