Skip to content

The insertion operation may have issues. #40

@xWX474260

Description

@xWX474260

const heap = new Heap((a, b) => a - b, [3, 1, 4])
heap.insert(2)
console.log(heap.toArray())
// Expected result: 1, 2, 4, 3; Actual result: 3, 1, 4, 2

const heap1 = new Heap((a, b) => a - b, [3, 1, 4])
heap1.insert(0)
console.log(heap1.toArray())
// Expected results: 0, 1, 4, 3; Actual results: 0, 3, 4, 1

const heap2 = new MinHeap()
;[3, 1, 4, 1, 5].forEach((n) => heap2.insert(n))

for (const num of heap2) {
console.log(num)
}
// The expected results are 1, 1, 4, 3, and 5. Actual result: 1, 1, 3, 4, 5

  1. Initialization did not perform heapification, and the insertion operation caused some values to float up.
  2. The heapification of the insertion operation was incorrect and did not match the predicted value.

Metadata

Metadata

Labels

bugSomething isn't working

Type

No type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions