Template <Class Type>
int binarySearch(Type a[] , const T&x , int left , int right , int &i , int &j)
{
int middle;
while(left <= right)
{
middle = (left + right) / 2;
if(x == a[middle])
{
i = j =middle;
return 1;
}
if(x < a[middle]) right = middle - 1;
else left = middle + 1;
}
return 0 ;
}
网友评论