排序之直接插入排序

/**
     * @Params :
     * @Author :scy
     * @Date :2019/6/20
     * description:直接插入排序
     */
    public static int[] directInsertSort(int[] array) {
        int len = array.length;
        int temp;
        int j;
        for (int i = 1; i < len; i++) {
            temp = array[i];//標記當前需要插入的數
            for (j = i; j > 0 && temp < array[j - 1]; j--) {//當前數小於前面數
                array[j] = array[j - 1];//那麼前面的數就後移
            }
            array[j] = temp;
        }
        return array;
    }

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章