Problem

How do you modify the selectionSort method in Listing 1 to sort numbers in decreasing orde...

How do you modify the selectionSort method in Listing 1 to sort numbers in decreasing order?

LISTING 1 SelectionSort.java

1 public class SelectionSort {

2 /** The method for sorting the numbers */

3 public static void selectionSort(double[] list) {

4 for (int i = 0; i1; i++) {

5 // Find the minimum in the list[i..list.length-1]

6 double currentMin = list[i];

7 int currentMinIndex = i;

8

9 for (int j = i + 1; j

10 if (currentMin > list[j]) {

11 currentMin = list[j];

12 currentMinIndex = j;

13 }

14 }

15

16 // Swap list[i] with list[currentMinIndex] if necessary

17 if (currentMinIndex != i) {

18 list[currentMinIndex] = list[i];

19 list[i] = currentMin;

20 }

21 }

22 }

23 }

Step-by-Step Solution

Request Professional Solution

Request Solution!

We need at least 10 more requests to produce the solution.

0 / 10 have requested this problem solution

The more requests, the faster the answer.

Request! (Login Required)


All students who have requested the solution will be notified once they are available.
Add your Solution
Textbook Solutions and Answers Search
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT