1 /** 2 * 插入排序 3 * @param a 4 * @date 2016-10-8 5 * @author shaobn 6 */ 7 public static void insertSort(int[] a){ 8 for(int i =1;i<a.length;i++){ 9 int j = i-1; 10 int t = a[i]; 11 while(t<a[j] && j>=0){ 12 if(j==0){ 13 a[j+1] = a[j]; 14 a[j] = t; 15 break; 16 } 17 a[j+1] = a[j]; 18 a[j] = t; 19 j--; 20 } 21 22 23 } 24 for(int num:a){ 25 System.out.println(num); 26 } 27 28 29 }