MCPcopy Index your code
hub / github.com/TheAlgorithms/Python / pop

Method pop

data_structures/heap/skew_heap.py:173–196  ·  view source on GitHub ↗

Pop the smallest value from the heap and return it. >>> sh = SkewHeap([3, 1, 3, 7]) >>> sh.pop() 1 >>> sh.pop() 3 >>> sh.pop() 3 >>> sh.pop() 7 >>> sh.pop() Traceback (most recent call last):

(self)

Source from the content-addressed store, hash-verified

171 self._root = SkewNode.merge(self._root, SkewNode(value))
172
173 def pop(self) -> T | None:
174 """
175 Pop the smallest value from the heap and return it.
176
177 >>> sh = SkewHeap([3, 1, 3, 7])
178 >>> sh.pop()
179 1
180 >>> sh.pop()
181 3
182 >>> sh.pop()
183 3
184 >>> sh.pop()
185 7
186 >>> sh.pop()
187 Traceback (most recent call last):
188 ...
189 IndexError: Can't get top element for the empty heap.
190 """
191 result = self.top()
192 self._root = (
193 SkewNode.merge(self._root.left, self._root.right) if self._root else None
194 )
195
196 return result
197
198 def top(self) -> T:
199 """

Callers 3

__iter__Method · 0.95
removeMethod · 0.45
extract_maxMethod · 0.45

Calls 2

topMethod · 0.95
mergeMethod · 0.45

Tested by

no test coverage detected