python - 我在 Python 中使用什么来实现最大堆?

标签 python data-structures heap recursive-datastructures

Python 包含用于最小堆的 heapq 模块,但我需要一个最大堆。我应该在 Python 中使用什么来实现最大堆?

最佳答案

最简单的方法是反转键的值并使用 heapq。例如,将 1000.0 变为 -1000.0,将 5.0 变为 -5.0。

关于python - 我在 Python 中使用什么来实现最大堆?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2501457/

相关文章:

python - 我怎样才能杀死我用 python 启动的进程

C++ 堆实现

Python 尝试除了最后

python - 在 python 中获取 N-many 列表的交集

string - 从没有空格和标点符号的字符串中取消连接单词的算法

algorithm - 为什么在CLRS中Q.head = Q.tail + 1表示队列已满

Java Arraylist 堆实现

C++堆组织——哪种数据结构?

python - conda env 中的 pip 错误

algorithm - 修改福特富尔克森算法的bfs,寻找增广路径