#include <stdio.h>
void zhebancharu(int k[],int n);
void print(int k[],int n);
int main(){
int K[]= {49,38,97,76,65,13,27,50};
zhebancharu(K,8);
print(K,8);
}
//折半插入法
void zhebancharu(int k[],int n){
int i,j,temp;
for (i=1;i<n;i++){
temp = k[i];
int high = i-1;
int low = 0;
//确定插入位置为low
while(low<=high){
int mid=(low+high)/2;
if(temp<k[mid]){
high=mid-1;
}else{
low=mid+1;
}
}
for(j=i-1;j>=low;j--){
k[j+1]=k[j];
}
k[low]=temp;
}
}
void print(int k[],int n){
for (int i=0;i<n;i++){
printf("%d\n",k[i]);
}
}