Insertion sort JAVA program

// Insertion sort program

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