How can I prevent a segmentation fault with a recursive binary search that does not find the number it it is looking for in the array.
int recursive_binary_search(int A[], int beg, int end, int key)
{
if(end < beg)
return -1;
int mid = beg + end / 2;
if(A[mid] == key)
return mid;
else if(A[mid] > key)
return recursive_binary_search(A, beg, mid - 1, key);
else
return recursive_binary_search(A, mid + 1, end, key);
}
std::exceptionat caller function?if(end <= beg)?