折半插入排序:
/**
* @author Jay
* @date 2020/7/13 10:28
* 插入排序
* @Description:折半插入排序
*/
public class binSort {
public int[] BinSort(int[] a) {
for (int i = 1; i < a.length; i++) {
int low=0,high=i-1,mid;
//查找位置
while (low<=high) {
mid = (low + high) / 2;
if (a[i] > mid) low = mid + 1;
else high = mid - 1;
}
//high+1为需要插入的点,所以hiigh+1到i-1都向后移一个位置
int temp=a[i];
for (int j = high+1; j <=i ; j++) {
a[j+1]=a[j];
}
a[high+1]=temp;
}
return a;
}
}