# how do i reverse this method for sorting?Again!

• 03-09-2009, 12:01 AM
PureAwesomeness
how do i reverse this method for sorting?Again!
in the previous thread i marked Solved and i realized that my problem not fully solved yet, so i post this thread again.

this method sorts numbers from smallest to biggest
and i want it to be the opposite from biggest to smallest
i tried to exchange places with the first and second for loop, but that doesn't seem to work.
doesnt anybody have any suggestion?

Code:

```public class SelectionSort {   /** The method for sorting the numbers */   public static void selectionSort(double[] list) {     for (int i = list.length - 1; i >= 1; i--) {       // Find the maximum in the list[0..i]       double currentMax = list[0];       int currentMaxIndex = 0;       for (int j = 1; j <= i; j++) {         if (currentMax < list[j]) {           currentMax = list[j];           currentMaxIndex = j;         }       }       // Swap list[i] with list[currentMaxIndex] if necessary;       if (currentMaxIndex != i) {         list[currentMaxIndex] = list[i];         list[i] = currentMax;       }     }   } }```

if i want to change the codes to do the opposite i need to change this?
Code:

``` if (currentMaxIndex != i) {         list[currentMaxIndex] = list[i];         list[i] = currentMax;```
how do I change the i though?
• 03-09-2009, 12:22 AM
Fubarable