MCPcopy Index your code
hub / github.com/TheAlgorithms/JavaScript / extractTop

Method extractTop

Data-Structures/Heap/BinaryHeap.js:109–119  ·  view source on GitHub ↗

* Removes and returns the top element of the heap. * @returns {*} - The top element of the heap.

()

Source from the content-addressed store, hash-verified

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.

Callers 1

BinaryHeap.test.jsFile · 0.80

Calls 4

peekMethod · 0.95
emptyMethod · 0.95
#sinkDownMethod · 0.95
popMethod · 0.45

Tested by

no test coverage detected