Selection sort JAVA program

// Selection sort program


public class SelectionSort {
   
   public static void main(String args[]) {
     
     int[] x =
     {547, 23, 523, 2378, 243, 7854, 14, 23, 310};
     
     System.out.println("Unsorted list: ");
     display(x);
         
     selectionSort(x);
     System.out.println("Sorted list: ");
     display(x);
   }
   
   private static void selectionSort(int x[]) {
     
     int n = x.length;
     int i, indx, j, large;
     
     large = x[0];
     indx = 0;
     
     for (i=n-1; i>0; i--) {
       
       large = x[0];
       indx = 0;
       
       for (j=1; jlarge) {
           large = x[j];
           indx = j;
         }
       x[indx] = x[i];
       x[i] = large;
     }
     
   }
   
   
   private static void display(int x[]) {
     for (int i=0; i<x.length; i++)
       System.out.print(x[i] + " ");
     System.out.println("\n");
   }
}
Advertisements