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:
Leandro Doctors
2021-04-20 22:23:46 -03:00
committed by GitHub
parent 02fab665de
commit d2d5efdd2a

View File

@ -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) {