用递归方法实现二分查找,为了避免异常情况,首先判断上下限范围
int binarysearch(int source[],int low,int,high,int targetvalue)
{
if (low>high) return;
int temp= (high-low)/2+low;
if(source[temp]>targetvalue)
binarysearch(source,low,temp-1,targetvalue);
else if(source[temp]<targetvalue)
binarysearch(source,temp+1,high,targetvalue);
else
return temp;
}