Method
select
(
int[] keys,
Map<Integer, Integer> map,
int left,
int right,
int kSmallest
)
Source from the content-addressed store, hash-verified
| 49 | // Modified implementation of Hoare's selection algorithm: |
| 50 | |
| 51 | private void select( |
| 52 | int[] keys, |
| 53 | Map<Integer, Integer> map, |
| 54 | int left, |
| 55 | int right, |
| 56 | int kSmallest |
| 57 | ) { |
| 58 | while (left != right) { |
| 59 | int pivot = partition(keys, map, left, right, (left + right) / 2); |
| 60 | |
| 61 | if (kSmallest == pivot) return; |
| 62 | |
| 63 | if (kSmallest < pivot) right = pivot - 1; else left = pivot + 1; |
| 64 | } |
| 65 | } |
| 66 | |
| 67 | private int partition( |
| 68 | int[] keys, |
Tested by
no test coverage detected