Skip to content

Commit 7dd977c

Browse files
committedApr 3, 2018
Add comments.
1 parent 9f8e763 commit 7dd977c

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed
 

‎src/data-structures/heap/MinHeap.js

+5
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,9 @@ export default class MinHeap {
7878
}
7979

8080
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.
8184
let currentIndex = this.heapContainer.length - 1;
8285

8386
while (
@@ -90,6 +93,8 @@ export default class MinHeap {
9093
}
9194

9295
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.
9398
let currentIndex = 0;
9499
let nextIndex = 0;
95100

0 commit comments

Comments
 (0)
Please sign in to comment.