[英]Dijkstra Algorithm in Java
I have some troubles implementing Dijkstra algorithm in Java. 我在用Java实现Dijkstra算法时遇到了一些麻烦。
I use this (first) pseudocode: http://en.wikipedia.org/wiki/Dijkstra%27s_algorithm 我使用此(第一个)伪代码: http : //en.wikipedia.org/wiki/Dijkstra%27s_algorithm
Line 15 you need to get the vertex with the lowest distance. 第15行需要获得最短距离的顶点。 But how can I save the distance with the according distance.
但是我该如何用相应的距离保存距离。
Note: vertex is defined as an Integer. 注意:顶点被定义为整数。
My solutions that didn't work properly: 我的解决方案无法正常工作:
So I am looking for a fast way to save a vertex to a distance and it should be easy to get the vertex with min dist. 因此,我正在寻找一种将顶点保存到一定距离的快速方法,并且应该容易获得具有最小距离的顶点。
Try using a PriorityQueue. 尝试使用PriorityQueue。 That way, you can simply remove the head, as it would have the minimum distance of all vertices.
这样,您可以简单地移除头部,因为它具有所有顶点的最小距离。
See more information about PriorityQueue here: http://docs.oracle.com/javase/7/docs/api/java/util/PriorityQueue.html 在此处查看有关PriorityQueue的更多信息: http : //docs.oracle.com/javase/7/docs/api/java/util/PriorityQueue.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.