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

Method top

data_structures/heap/skew_heap.py:198–218  ·  view source on GitHub ↗

Return the smallest value from the heap. >>> sh = SkewHeap() >>> sh.insert(3) >>> sh.top() 3 >>> sh.insert(1) >>> sh.top() 1 >>> sh.insert(3) >>> sh.top() 1 >>> sh.insert(7) >>> sh.top()

(self)

Source from the content-addressed store, hash-verified

196 return result
197
198 def top(self) -> T:
199 """
200 Return the smallest value from the heap.
201
202 >>> sh = SkewHeap()
203 >>> sh.insert(3)
204 >>> sh.top()
205 3
206 >>> sh.insert(1)
207 >>> sh.top()
208 1
209 >>> sh.insert(3)
210 >>> sh.top()
211 1
212 >>> sh.insert(7)
213 >>> sh.top()
214 1
215 """
216 if not self._root:
217 raise IndexError("Can't get top element for the empty heap.")
218 return self._root.value
219
220 def clear(self) -> None:
221 """

Callers 1

popMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected