Skip to content

Commit c20acfb

Browse files
Merge pull request #114 from Balaji1202/patch-1
fix(heap.js): makes it easier to reason and avoids negative zero `-0` case.
2 parents 41205d6 + cde6e8a commit c20acfb

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/data-structures/heaps/heap.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ class Heap {
5959
*/
6060
bubbleUp() {
6161
let index = this.size - 1;
62-
const parent = (i) => Math.ceil(i / 2 - 1);
62+
const parent = (i) => Math.ceil(i / 2) - 1;
6363
while (parent(index) >= 0 && this.comparator(parent(index), index) > 0) {
6464
this.swap(parent(index), index);
6565
index = parent(index);

0 commit comments

Comments
 (0)