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; i
1; 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 }
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.