i'm stuck in binary search. Check50 doesn't pass all the checks and it doesn't find the needle, I feel like the algorithm i have implemented is correct but it doesn't work. I've been stuck in this for a while. Can anyone please have a look on this and help me out, thanks!
bool search(int value, int values[], int n)
{
// TODO: implement a searching algorithm
int start,mid,end;
if(n < 0)
{
return 1;
}
start = 0;
end = n - 1;
while(start < end)
{
mid = values[(start+end)/2];
if(value == mid)
{
return true;
}
if(value < mid)
{
end = mid - 1;
}
if(value > mid)
{
start = mid + 1;
}
}
return false;
}