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.

Computer Science & Information Technology

You might also like to view...

What code is used within the IPv6 routing table to distinguish a per-user static route?

A) C B) U C) L D) S

Computer Science & Information Technology

You can use a Slide Library to store favorite slides that you want to reuse again and again.

Answer the following statement true (T) or false (F)

Computer Science & Information Technology

What items should be included on a network diagram?

What will be an ideal response?

Computer Science & Information Technology

In the figure above, the name of the book is Entrees.

Answer the following statement true (T) or false (F)

Computer Science & Information Technology