Skip to content

Commit cde6e8a

Browse files
authored
Update heap.js
Fix proper parent index fetching
1 parent ae41553 commit cde6e8a

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

Diff for: 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)