void insertSort(int arr[],size_t len){
for(int i=1;i<len;i++){//把arr[i..len-1]这些元素插入到前面使用[0,i]有序
int data = arr[i];//要插入的值
int j = i-1;
//arr[j]比要插入的元素大 arr[j]要往后移一个位置
for(;j>=0 && arr[j]>data;--j){
arr[j+1] = arr[j];
}
arr[j+1] = data;
}
}
折半插入
void binaryInsertSort(int arr[],size_t len){
for(int i=1;i<len;i++){
int right = i-1;
int left = 0;
int data = arr[i];
while(left<=right){
int mid = (left+right)/2;
if(data < arr[mid]){
right = mid-1;
}else{
left = mid+1;
}
}
//left > right
int j = i-1;
for(;j>right;j--){//j>=left
arr[j+1] = arr[j];
}
arr[j+1] = data;
}
}