#include <iostream>
using namespace std;
int main(void)
{
int n,k,mid,midval,low,high,x;
cin>>n;
k=n;
int *a=new int[n];
for(int i=0; i<n; i++)
a[i]=k--;
for(int i=1; i<n; i++)
{
x=a[i];
low=0,high=i-1;
while(low<=high)
{
mid=low>>2+high>>2;
midval=a[mid];
if(midval>x)
high=mid-1;
else
low=mid+1;
}
for(int j=i-1; j>=low; j--)
a[j+1]=a[j];
a[low]=x;
}
for(int i=0; i<n; i++)
cout<<a[i]<<" ";
}
折半插入排序
最新推荐文章于 2024-07-25 13:01:18 发布