Skip to content

Commit d73ee43

Browse files
authored
Fix heapify error
Heapify function error, heapify([2, 5, 4, 1, 3, 6]) result is [ 2, 1, 4, 5, 3, 6 ], should be [1, 2, 4, 5, 3, 6] test case ```js it('heapify test', () => { let arr = [2, 5, 4, 1, 3, 6] expect(heap.heapify(arr)).to.deep.equal([1, 2, 4, 5, 3, 6]) }) ```
1 parent cc55deb commit d73ee43

File tree

1 file changed

+1
-1
lines changed
  • LearningJavaScriptDataStructuresandAlgorithmsThirdEdition_Code/src/js/data-structures

1 file changed

+1
-1
lines changed

LearningJavaScriptDataStructuresandAlgorithmsThirdEdition_Code/src/js/data-structures/heap.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ export class MinHeap {
8888
this.heap = array;
8989
}
9090
const maxIndex = Math.floor(this.size() / 2) - 1;
91-
for (let i = 0; i <= maxIndex; i++) {
91+
for (let i = maxIndex; i >= 0; i--) {
9292
this.siftDown(i);
9393
}
9494
return this.heap;

0 commit comments

Comments
 (0)