IndexedSorter check bound
Opened this issue · 0 comments
cddesire commented
given range of items using heap sort
private static void downHeap(final IndexedSortable s, final int b,
int i, final int N) {
for (int idx = i << 1; idx < N; idx = i << 1) {
if (idx + 1 < N && s.compare(b + idx, b + idx + 1) < 0) {
if (s.compare(b + i, b + idx + 1) < 0) {
s.swap(b + i, b + idx + 1);
} else return;
i = idx + 1;
} else if (s.compare(b + i, b + idx) < 0) {
s.swap(b + i, b + idx);
i = idx;
} else return;
}
}