【java数据结构】插入排序

/**
     * 插入排序
     * @param arr
     * 原数组
     */
    public static void insertSort(int[] arr) {
        int target ;//待插入的
        int j;
        for(int i=1;i<arr.length;i++) {//假设第一个已经有序
            j=i;
            target = arr[i];
            while(j>0 && arr[j -1]>target) {//后移到第一个位置或者待插入的小于前面已经排序好的结束循环
                arr[j] = arr[j-1];
                j--;
            }   
            arr[j] = target;//插入
        }
    }
原文地址:https://www.cnblogs.com/cnsec/p/13286790.html