返回值的问题。
#include <stdio.h>void main()
{
int bit(int x,int v[],int n);
int v[]={1,2,3,4,5,6,8,9,12,13,15,18,19,21,24,26,29,36,38,39,40,51,52,53,54,58};
int x=45,n=26;
printf("%d",bit(x,v,n));
}
int bit(int x,int v[],int n)
{
int low=0,high=n-1,mid;
while(low<=high)
{
mid=(low+high)/2;
if(x<v[mid])
high=mid-1;
else if(x>v[mid])
low=mid+1;
else
return mid;
}
return -1;
}
此函数是否只能有一个返回值,当 return mid成立了,return -1是否就没用了。