插入排序实例

  

public static void sort2(int[] arr) {
        int temp,j;
        for (int i = 1; i < arr.length; i++) {//i:每次大的排序的部数
            temp= arr[i];
            j= i-1;
            while (j>=0 && temp<arr[j] ) {//移位
                arr[j+1]= arr[j];
                j--;
            }
            arr[j+1]= temp;
            System.out.println("第"+ i+ "步排序结果:"+ Arrays.toString(arr));
        }
    }
原文地址:https://www.cnblogs.com/westward/p/5890123.html