mirror of
https://github.com/TheAlgorithms/Java.git
synced 2025-07-06 09:06:51 +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
|
||||
|
||||
// find median
|
||||
int median = left + ((right - left) >>> 1);
|
||||
int median = (left + right) >>> 1;
|
||||
int comp = key.compareTo(array[median]);
|
||||
|
||||
if (comp == 0) {
|
||||
|
Reference in New Issue
Block a user