I have to implement Binary search method which finds if value is or isn't in array. I have to use recurse.
public static boolean searchBin(int[] array, int x, int l, int r) {
int center;
center =(l+r) / 2;
if ( x > array[center] )
{
l = center+1;
}
else
{
r = center-1;
}
if ( array[center] == x )
{
return true;
}
else
{
if ( l<=r )
{
searchBin(array,x,l,r);
}
else
{
return false;
}
}
}
I'm getting the following error:
Missing return statement
Thanks.
returnanything. But the method shouldreturnsomething..return searchBin(array,x,l,r);?