We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 9f8e763 commit 7dd977cCopy full SHA for 7dd977c
src/data-structures/heap/MinHeap.js
@@ -78,6 +78,9 @@ export default class MinHeap {
78
}
79
80
heapifyUp() {
81
+ // Take last element (last in array or the bottom left in a tree) in
82
+ // a heap container and lift him up until we find the parent element
83
+ // that is less then the current new one.
84
let currentIndex = this.heapContainer.length - 1;
85
86
while (
@@ -90,6 +93,8 @@ export default class MinHeap {
90
93
91
94
92
95
heapifyDown() {
96
+ // Compare the root element to its children and swap root with the smallest
97
+ // of children. Do the same for next children after swap.
98
let currentIndex = 0;
99
let nextIndex = 0;
100
0 commit comments