mirror of
https://github.com/TheAlgorithms/Java.git
synced 2025-07-08 02:04:31 +08:00
BinarySearch: clearer median computation (#2182)
* BinarySearch: clearer median computation ">>> 1" is simply too obscure... * update binary search Co-authored-by: Yang Libin <contact@yanglibin.info> Co-authored-by: Du Yuanchao <shellhub.me@gmail.com> Co-authored-by: Yang Libin <contact@yanglibin.info>
This commit is contained in:
@ -45,7 +45,7 @@ class BinarySearch implements SearchAlgorithm {
|
|||||||
if (right < left) return -1; // this means that the key not found
|
if (right < left) return -1; // this means that the key not found
|
||||||
|
|
||||||
// find median
|
// find median
|
||||||
int median = left + ((right - left) >>> 1);
|
int median = (left + right) >>> 1;
|
||||||
int comp = key.compareTo(array[median]);
|
int comp = key.compareTo(array[median]);
|
||||||
|
|
||||||
if (comp == 0) {
|
if (comp == 0) {
|
||||||
|
Reference in New Issue
Block a user