1 2 3 public class MyInsertSort { 4 public static void main(String[] args) { 5 int num[] = {10, 8, 33, 54, 1, 6, 12, 43, 32, 27}; 6 insertSort(num); 7 for (int i = 0; i < num.length; i++) { 8 System.out.print(num[i] + " "); 9 } 10 } 11 12 private static void insertSort(int[] num) { 13 for (int i = 1; i < num.length; i++) { 14 int key = num[i]; 15 int j = i - 1; 16 while (j>=0&&num[j]>key){ 17 num[j+1] = num[j]; 18 j--; 19 } 20 num[j+1] = key; 21 } 22 } 23 }