MCPcopy Index your code
hub / github.com/trekhleb/javascript-algorithms / poll

Method poll

src/data-structures/heap/Heap.js:117–133  ·  view source on GitHub ↗

* @return {*}

()

Source from the content-addressed store, hash-verified

115 * @return {*}
116 */
117 poll() {
118 if (this.heapContainer.length === 0) {
119 return null;
120 }
121
122 if (this.heapContainer.length === 1) {
123 return this.heapContainer.pop();
124 }
125
126 const item = this.heapContainer[0];
127
128 // Move the last element from the end to the head.
129 this.heapContainer[0] = this.heapContainer.pop();
130 this.heapifyDown();
131
132 return item;
133 }
134
135 /**
136 * @param {*} item

Callers 8

MinHeap.test.jsFile · 0.45
MaxHeap.test.jsFile · 0.45
sortMethod · 0.45
dijkstraFunction · 0.45
primFunction · 0.45

Calls 2

heapifyDownMethod · 0.95
popMethod · 0.80

Tested by

no test coverage detected