From 7dd977c3a4466895c35611c76e3d6e9ae391eb2e Mon Sep 17 00:00:00 2001 From: Oleksii Trekhleb Date: Tue, 3 Apr 2018 16:51:58 +0300 Subject: [PATCH] Add comments. --- src/data-structures/heap/MinHeap.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/data-structures/heap/MinHeap.js b/src/data-structures/heap/MinHeap.js index 73e2a22d..05d7f38a 100644 --- a/src/data-structures/heap/MinHeap.js +++ b/src/data-structures/heap/MinHeap.js @@ -78,6 +78,9 @@ export default class MinHeap { } heapifyUp() { + // Take last element (last in array or the bottom left in a tree) in + // a heap container and lift him up until we find the parent element + // that is less then the current new one. let currentIndex = this.heapContainer.length - 1; while ( @@ -90,6 +93,8 @@ export default class MinHeap { } heapifyDown() { + // Compare the root element to its children and swap root with the smallest + // of children. Do the same for next children after swap. let currentIndex = 0; let nextIndex = 0;