我試圖使用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 =