We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent d168bf0 commit f244049Copy full SHA for f244049
src/data_structures/priority_queue.js
@@ -55,14 +55,12 @@ class PriorityQueue {
55
*/
56
_fixBottomHeap(idx) {
57
let changeIdx = idx;
58
- let childIdx = idx * 2 + 1;
59
- let rightChildIdx = idx * 2 + 2;
60
- while (childIdx <= rightChildIdx) {
61
- if (childIdx < this._size && this.comparison(
+ let maxChildIdx = Math.min(idx*2 + 2, this._size - 1);
+ for (let childIdx = idx*2 + 1; childIdx <= maxChildIdx; childIdx++) {
+ if (this.comparison(
62
this._priorityHeap[childIdx], this._priorityHeap[changeIdx])) {
63
changeIdx = childIdx;
64
}
65
- childIdx++;
66
67
68
if (changeIdx != idx) {
0 commit comments