MCPcopy Index your code
hub / github.com/TheAlgorithms/JavaScript / #bubbleUp

Method #bubbleUp

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

* Bubbles up a value from the specified index to maintain the heap property. * @param {number} currIdx - The index of the value to be bubbled up. * @private

(currIdx)

Source from the content-addressed store, hash-verified

56 * @private
57 */
58 #bubbleUp(currIdx) {
59 let parentIdx = Math.floor((currIdx - 1) / 2)
60
61 while (
62 currIdx > 0 &&
63 this.comparator(this.heap[currIdx], this.heap[parentIdx])
64 ) {
65 this.#swap(currIdx, parentIdx)
66 currIdx = parentIdx
67 parentIdx = Math.floor((currIdx - 1) / 2)
68 }
69 }
70
71 /**
72 * Sinks down a value from the specified index to maintain the heap property.

Callers 1

insertMethod · 0.95

Calls 1

#swapMethod · 0.95

Tested by

no test coverage detected