I am trying to create a binary search algorithm using recursion in Java, when debugging everything seems to be okay up until it finds the value and should return the index of the key needed. However, for some reason it skips the return statement and goes to the bottom return statement.
public int binSearch(int key, int L, int R) {
int mid =(R + L)/2;
if (R < L) {
return -1;
}
if (A[mid] == key) {
return mid;
}
if (key > A[mid]) {
binSearch(key, mid + 1, R);
}
if (key < A[mid]) {
binSearch(key, L, mid - 1);
}
return -1;
}