Working on pset3 and tried to write a separate binary search function in helpers.c so I can just call it later in the main search function. Here's my code for the binary search:
bool binarysearch(int target, int array[], int start, int end);
{
//make sure array exists
if (array != NULL)
{
//makes sure array has remaining values to search
if (start > end)
return false;
else
{
//define midpoint
int mid = (start + end)/2;
//if midpoint is target, return true
if (array[mid] == target)
{
return true;
}
//if midpoint is greater than target, search left
else if (array[mid] > target)
{
return binarysearch(target, array, start, mid - 1);
}
//if midpoint is less than target, search right
else if (array[mid] < value)
{
return binarysearch(target, array, mid + 1, end);
}
}
}
And here's the call in the same file:
bool search(int value, int values[], int n)
{
if (binarysearch(value, values, 0, n) == true)
return true;
else
return false;
}
When I try to make find in my terminal, it returns a top error of "error: control reaches end of non-void function." Where am I going wrong? Is the binary search itself broken or am I calling it wrong in search? Thanks in advance!