排序算法(对半)
#include<stdio.h>main()
{ int i,j,temp, low,high,mid,a[100],n;
printf("请问你要输入几个数字:\n");
scanf("%d",&n);
printf("请输入数字:\n");
for(i=0;i<n;i++)
scanf("%d",&a[i]);
for(i=1;i<n;i++)
{ temp=a[i];
low=0;
high=i-1;
while(high>=low)
{ mid=(low+high)/2;
if(temp<a[mid]) high=mid-1;
else
low=mid+1;
}
for(j=i-1;j>=low;j--)
a[j+1]=a[j];
a[low]=temp;
}
printf("排序后的:\n");
for(i=0;i<n;i++)
printf("%d\t",a[i]);
}