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...
Describe the process that the admissions office of your university uses to admit new students as a workflow. Decompose the process into tasks, and describe the task interaction using a diagram similar to Figure 19.9.
What will be an ideal response?
Explain how to finalize your video for DVDs.
What will be an ideal response?