I am struggling to implement the recursive binary search function: We are not supposed to change the search()
declaration, so I thought I will have to implement a separate recursive function for binary search. I think my sort function works ok and my code for binarysearch()
is correct and will return true (not posting it here), but it seems that isn't passed back to search and hence find
always gets the message that the needle wasn't found. I am not sure how to better implement this, hope someone can point me in the right direction, please?
bool search(int value, int values[], int n)
{
if (n <= 0)
{
return -1;
}
else
{
int min = 0;
int max = n - 1;
return binarysearch(value, values, min, max);
}
}