package 排序算法;
import java.util.Arrays;
public class BinaryInsertSort {
public static void main(String[] args) {
int[] arr = { 3, 2, 1 ,4,5};
int low;
int high = 0;
int mid;
int tmp;
for (int i = 1; i < arr.length; i++) {
tmp=arr[i];
low=0;
high=i-1;
while(low<=high){
mid=(low+high)/2;
if(arr[mid]>tmp){
high=mid-1;
}else{
low=mid+1;
}
}
int j=i-1;
while(j>high){
arr[j+1]=arr[j];
j--;
}
arr[high+1]=tmp;
}
System.out.println(Arrays.toString(arr));
}
}
import java.util.Arrays;
public class BinaryInsertSort {
public static void main(String[] args) {
int[] arr = { 3, 2, 1 ,4,5};
int low;
int high = 0;
int mid;
int tmp;
for (int i = 1; i < arr.length; i++) {
tmp=arr[i];
low=0;
high=i-1;
while(low<=high){
mid=(low+high)/2;
if(arr[mid]>tmp){
high=mid-1;
}else{
low=mid+1;
}
}
int j=i-1;
while(j>high){
arr[j+1]=arr[j];
j--;
}
arr[high+1]=tmp;
}
System.out.println(Arrays.toString(arr));
}
}