* Removes and returns the top element of the heap. * @returns {*} - The top element of the heap.
()
| 107 | * @returns {*} - The top element of the heap. |
| 108 | */ |
| 109 | extractTop() { |
| 110 | const top = this.peek() |
| 111 | const last = this.heap.pop() |
| 112 | |
| 113 | if (!this.empty()) { |
| 114 | this.heap[0] = last |
| 115 | this.#sinkDown(0) |
| 116 | } |
| 117 | |
| 118 | return top |
| 119 | } |
| 120 | |
| 121 | /** |
| 122 | * Swaps elements at two specified indices in the heap. |
no test coverage detected