package Myjava;
public class BinaryInsertSort {
public void sort(int[] data){
for(int i=1;i<data.length;i++){
int temp=data[i];
int low=0;
int high=i-1;
while(low<=high){
int mid=low+(high-low)/2;
if(temp-data[mid]>0){
low=mid+1;
}
if(temp-data[mid]<0){
high=mid-1;
}
}
for(int j=i;j>low;j--){
data[j]=data[j-1];
}
data[low]=temp;
}
}
public static void main(String[] args) {
int[] num={49,38,65,97,76,13 ,27};
BinaryInsertSort binaryInsertSort=new BinaryInsertSort();
binaryInsertSort.sort(num);
System.out.println(java.util.Arrays.toString(num));
}
}
折半插入排序
于 2018-10-11 20:32:30 首次发布