This is a C program with the recursive binary search algorithm, however when I run it, the debugger says there is an access segmentation fault in the binary search function. Why is this and how do I fix this?
Here is the recursive binary search function:
int binSearch(int val, int numbers[], int low, int high)
{
int mid;
mid=(low+high)/2;
if(val==numbers[mid])
{
return(mid);
}
else if(val<numbers[mid])
{
return(binSearch(val, numbers, low, mid-1));
}
else if(val>numbers[mid])
{
return(binSearch(val, numbers, mid+1, high));
}
else if(low==high)
{
return(-1);
}
}
Thank you :)