Introduction to Algorithms Notes - 2.3.3 insertion sort - Ascending

@Test
    public void insertionSort() {
        Integer[] a = {5,9,3,4,2,1,6,8,10,7,65,54,85,32,15,94,75,62,34,76,45,32,85};
        for(int i = 1; i<a.length; i++){
            int key = a[i];
            int j = i - 1;
//循环不变式 while (j >= 0 && a[j]>key){ a[j+1] = a[j]; a[j] = key; j = j-1; } } System.out.print(Arrays.toString(a)); }

  

Focus insertion algorithm: loop invariant for small amounts of data

Guess you like

Origin www.cnblogs.com/lishiwei/p/12064649.html