Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c822875

Browse files
Fix heap "update" method
1 parent 8cc3231 commit c822875

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

src/data-structures/heap.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,8 @@
8282
}
8383

8484
if (right < this._heap.length &&
85-
this._cmp(this._heap[right], this._heap[index]) > 0) {
85+
this._cmp(this._heap[right], this._heap[index]) > 0 &&
86+
this._cmp(this._heap[right], this._heap[left]) > 0) {
8687
extr = right;
8788
}
8889

@@ -116,6 +117,7 @@
116117
index = parent;
117118
parent = Math.floor(parent / 2);
118119
}
120+
this._heapify(index);
119121
}
120122
return parent;
121123
};

0 commit comments

Comments
 (0)