比给定数字小的
int bin_search(int key)
{
int l,r;
l = 1;
r = 5;
int mid;
while(l<r)
{
mid = (l+r)>>1;
if(a[mid] >= key)
r = mid-1;
else
l = mid;
}
return l;
}
比给定数字大的
int bin_search(int key)
{
int l,r;
l = 1;
r = 5;
int mid;
while(l<r)
{
mid = (l+r)>>1;
if(a[mid] >= key)
r = mid;
else
l = mid+1;
}
return l;
}