@songying
2019-06-10T16:20:38.000000Z
字数 313
阅读 1234
python库
python中只有最小堆, 如果想使用大根堆, 需要将元素 按照 -num 存取。
| 函数 | 说明 |
|---|---|
| nlargest(n, iterable) | 查询堆中的最大元素,n表示查询个数 |
| nsmallest(n, iterable) | 查询堆中的最小元素,n表示查询元素个数 |
| heappush(heap, item) | 将item插入堆中 |
| heappop(heap) | 删除最小值, heap[0] |
| heappushpop(heap,item) | 先 push item, 然后pop并返回heap中最小的值 |
| heapify(x) | 将列表转换为堆 |
| heapreplace(heap, item) | 删除最小元素 heap[0], 并添加新的元素 |
| merge(...) | 合并多个堆 |
