九种排序——折半插入排序(稳定)
#include<iostream>
#include <cstring>
using namespace std;
void BInterSort(int A[],int n) {
int i,j;
int low,high,mid;
for(i=2 ;i<= n;i++){
A[0]=A[i];
low=1;high=i-1;
while(low<=high)
{
mid=(low+high)/2;
if(A[mid]>A[0]){
high = mid-1;
}
else{
low=mid+1;
}
}
for(j=i-1;j>=high+1;j--){
A[j+1]=A[j];
}
A[high+1]=A[0];
for(int k=1;k<= n;k++)
{
cout<<A[k]<<" ";
}
cout << endl;
}
}
int main()
{
int a[]={0,15,36,11,8,25,35,19}; //数组从第二位开始记录
BInterSort(a,7);
}