二分排序
直接贴代码
#include"stdio.h"
#include"string.h"
int main()
{
int n=5;
int a[5]= {81,60,51,35,73};
int q=n,m,p,s,k,i=0,temp;
while(q)
{
p=n;
while(p)
{
k=p,m=0,s=1;
while(k/2)
{
k=k/2;
m++;
}
while(k<=m)
{
s=s*2;
k++;
}
i=s-1;
while(i+s<n)
{
if(a[i+s]<a[i])
{
temp=a[i+s];
a[i+s]=a[i];
a[i]=temp;
}
else if(a[i+s]>a[i+s+1]&&(i+s+1)<n)
{
temp=a[i+s];
a[i+s]=a[i+s+1];
a[i+s+1]=temp;
}
i++;
}
p=p/2;
}
q=q/2;
}
for(i=0; i<n; i++)
printf("%d ",a[i]);
return 0;
}