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)
| 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 | """ |