Pop the smallest value from the heap and return it. >>> rh = RandomizedHeap([3, 1, 3, 7]) >>> rh.pop() 1 >>> rh.pop() 3 >>> rh.pop() 3 >>> rh.pop() 7 >>> rh.pop() Traceback (most recent call last):
(self)
| 123 | self._root = RandomizedHeapNode.merge(self._root, RandomizedHeapNode(value)) |
| 124 | |
| 125 | def pop(self) -> T | None: |
| 126 | """ |
| 127 | Pop the smallest value from the heap and return it. |
| 128 | |
| 129 | >>> rh = RandomizedHeap([3, 1, 3, 7]) |
| 130 | >>> rh.pop() |
| 131 | 1 |
| 132 | >>> rh.pop() |
| 133 | 3 |
| 134 | >>> rh.pop() |
| 135 | 3 |
| 136 | >>> rh.pop() |
| 137 | 7 |
| 138 | >>> rh.pop() |
| 139 | Traceback (most recent call last): |
| 140 | ... |
| 141 | IndexError: Can't get top element for the empty heap. |
| 142 | """ |
| 143 | |
| 144 | result = self.top() |
| 145 | |
| 146 | if self._root is None: |
| 147 | return None |
| 148 | |
| 149 | self._root = RandomizedHeapNode.merge(self._root.left, self._root.right) |
| 150 | |
| 151 | return result |
| 152 | |
| 153 | def top(self) -> T: |
| 154 | """ |
no test coverage detected