mirror of
https://github.com/TheAlgorithms/Java.git
synced 2025-07-08 18:32:56 +08:00
@ -58,15 +58,13 @@ class BinarySearch implements SearchAlgorithm {
|
||||
int median = (left + right) >>> 1;
|
||||
int comp = key.compareTo(array[median]);
|
||||
|
||||
if (comp < 0) {
|
||||
if (comp == 0) {
|
||||
return median;
|
||||
} else if (comp < 0) {
|
||||
return search(array, key, left, median - 1);
|
||||
}
|
||||
|
||||
if (comp > 0) {
|
||||
} else {
|
||||
return search(array, key, median + 1, right);
|
||||
}
|
||||
|
||||
return median;
|
||||
}
|
||||
|
||||
// Driver Program
|
||||
|
Reference in New Issue
Block a user