help With Java SelectionSort numbers to display ascending and descending Order.
This is the program _ i want to put this in descending order,
Pls help me as soon as possible....
// program to demonstrate the selection sort
class SelectionSort { // method to display the contents of an array static void displayData(int[] data) { for (int index=0; index != data.length; index++) System.out.println(data[index]+"\t"); } static int positionOfLargest(int[] data, int limit) { // method to return the position of the largest item // in the data with bounds 0..limit int largest = data[0]; int indexOfLargest = 0; for (int index=1; index <= limit; index++) { if (data[index]> largest) { largest = data[index]; indexOfLargest = index; } } return indexOfLargest; } public static void selectionSort(int[] data) { // method to sort the contents of an data into // scending order int temporary; int position; int size=data.length; for (int index=size-1; index > 0; index--) { position=positionOfLargest(data, index); // swap numbers if (index != position) { temporary = data[index]; data[index] = data[position]; data[position] = temporary; } } } public static void main(String[] args) { int[] data = {18,7,15,8,13}; System.out.println("numbers before being sorted\n"); displayData(data); selectionSort(data); System.out.println("numbers after being sorted\n"); displayData(data); } }
Change the sort in descending Order?