刘汝佳 紫书提供方法:
//正确答案在[x,y)区间之内,即不会包括y。
//这种方法老是两个细节搞不顺,如下标注
int bsearch(int* a, int x,int y,int test)
{
int m;
while(x<y) //1.这里判断条件为什么不是x<=y(因为不包括y,所以x==y时就说明区间内没有正确答案了
{
m = (x+y)/2;
if(a[m]==test)
return m;
else if(a[m]>test)
y=m; //2.为什么不是y=m-1,=(因为区间y不可能是正确答案,m