Can someone help me fix this? I’m getting an IndexArrayOutofBounds error…
private static int recursiveBinarySearch(book[] book, String title) {
int low = 0, high = book.length - 1, middle = (low + high) / 2;
String bookTitle = title;
book[] newBook = new book[middle];
if (bookTitle.compareTo(book[middle].getTitle()) == 0) // base case
return middle;
else { // recursive
if (bookTitle.compareTo(book[middle].getTitle()) < 0) {
for (int i = 0; i < (book.length / 2); i++) {
newBook[i] = book[i]; // must be new array = to old array
}
}
else {
for (int i = (book.length / 2); i < book.length; i++) {
newBook[i] = book[i];
}
}
return (recursiveBinarySearch(newBook, bookTitle));
}
}