我试图使用heapq模块(https://docs.python.org/3/library/heapq.html)中的Python(2.0)内置最小堆数据结构来构建最大堆。要做到这一点,我只需使用我需要的数字的负数来推入我的堆。 使用这个(最大堆版本): import heapq
h=[]
for i in xrange(10):
heapq.heappush(h,-i)
我有最小堆的Dijkstra的实现,我试图改变最小堆到最大堆找到最大路径,但我不能,输出是错误的 所以,请你能帮我改变这个实现到最大堆? 非常感谢 public class DikjstraAlgorithm {
public static void main(String[] args) {
Graph graph = new Graph(9);
for (int i =