插入排序

 public static void main(String[] args) {
        int[] arr = {9,7,5,76,45,12,44,65,78};
        for (int i = 1; i <arr.length ; i++) {
            int insert = arr[i];
            int index = i -1;
            while (index>=0&&insert<arr[index]){
                arr[index+1] = arr[index];
                index--;
            }
            arr[index+1] = insert;

        }
        System.out.println(Arrays.toString(arr));
    }

你可能感兴趣的:(插入排序,代码积累)