MCPcopy Create free account
hub / github.com/TheAlgorithms/Python / top

Method top

data_structures/heap/randomized_heap.py:153–173  ·  view source on GitHub ↗

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

(self)

Source from the content-addressed store, hash-verified

151 return result
152
153 def top(self) -> T:
154 """
155 Return the smallest value from the heap.
156
157 >>> rh = RandomizedHeap()
158 >>> rh.insert(3)
159 >>> rh.top()
160 3
161 >>> rh.insert(1)
162 >>> rh.top()
163 1
164 >>> rh.insert(3)
165 >>> rh.top()
166 1
167 >>> rh.insert(7)
168 >>> rh.top()
169 1
170 """
171 if not self._root:
172 raise IndexError("Can't get top element for the empty heap.")
173 return self._root.value
174
175 def clear(self) -> None:
176 """

Callers 1

popMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected