thorax232

Java - Insertion Sort

Nov 13th, 2013
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.25 KB | None | 0 0
  1. public static long insertionSort(int[] list) {
  2.     int i, j, key;
  3.    
  4.     for(j = 1; j < list.length; j++) {
  5.         key = list[j];
  6.         for(i = j - 1; (i >= 0) && (list[i] > key); i--) {
  7.             list[i + 1] = list[i];
  8.         }
  9.         list[i + 1] = key;
  10.     }
  11.        
  12.     return list;
  13. }
Advertisement
Add Comment
Please, Sign In to add comment