1. 程式人生 > >折半插入排序

折半插入排序

blog temp for span post gpo pan ret []

    public static int[] BInsertSort(int[] arr){
        for(int i=1;i<arr.length;i++){
            int temp = arr[i];
            int j;
            int low = 0, high = i-1;
            while(low <= high){
                int m = (low + high)/2;
                if(temp < arr[m]){
                    high 
= m-1; }else{ low = m+1; } } for(j=i-1;j>=high+1;j--){ arr[j+1] = arr[j]; } arr[j+1] = temp; } return arr; }

折半插入排序