int BinSrch(int a)
{
int top=0;
int bottom=ROWS-1;
int mid=bottom+(top-bottom)/2;
if(data[top]>a||data[bottom]<a)
{
printf("不在查找范围\n");
return -1;
}
while(top!=bottom)
{
if(data[mid]==a)
return mid;
else if(data[mid]<a)
{
top=mid;
mid=(top+bottom)/2;
}
else if(data[mid]>a)
{
bottom=mid;
mid=bottom+(top-bottom)/2; //这里要注意两个大数相加有可能会溢出
}
}
return -1;
}
03-16