int CRandom::binarySearch(int bs[], int n, int target)
{
int first(0); int last(n-1); int mid;
while(first<=last)
{
cnt++;
mid = (first+last)/2;
if(target==bs[mid])
/* if(a==-1){
printf("dd");
return (mid-(100-a));}
else*/
return mid;
else if(target<bs[mid])
last=mid-1;
else
first=mid+1;
}
return -1;
}
{
int first(0); int last(n-1); int mid;
while(first<=last)
{
cnt++;
mid = (first+last)/2;
if(target==bs[mid])
/* if(a==-1){
printf("dd");
return (mid-(100-a));}
else*/
return mid;
else if(target<bs[mid])
last=mid-1;
else
first=mid+1;
}
return -1;
}
댓글 달기