Java Priority Queue reordering when editing elements

后端 未结 6 1128
陌清茗
陌清茗 2020-11-29 06:23

I\'m trying to implement Dijkstra\'s algorithm for finding shortest paths using a priority queue. In each step of the algorithm, I remove the vertex with the shortest distan

6条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-11-29 07:00

    The problem is that you update the distances array, but not the corresponding entry in the queue. To update the appropriate objects in the queue, you need to remove and then add.

提交回复
热议问题