Advertisement
Techmo

Insertion Sort

Jan 7th, 2015
286
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.38 KB | None | 0 0
  1.  public static void insertion(int array[])
  2.     {
  3.         int n = array.length;
  4.         for (int j = 1; j < n; j++)
  5.         {
  6.             int key = array[j];
  7.             int i = j-1;
  8.             while ( (i > -1) && ( array [i] > key ))
  9.             {
  10.                 array [i+1] = array [i];
  11.                 i--;
  12.             }
  13.             array[i+1] = key;
  14.         }
  15.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement