Skip to content

Commit fbd2d69

Browse files
author
zouyun
committed
update dijkstra
1 parent 13441bc commit fbd2d69

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

src/graphs/shortest-path/dijkstra.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,19 +92,18 @@
9292
* var shortestDist = dijkstra(0, 2, distMatrix); // 9
9393
*/
9494
return function (src, dest, graph) {
95-
var tempDistance = 0;
95+
var tempDistance = 0;
9696
init(src, graph);
9797
while (current.node !== dest && isFinite(current.distance)) {
9898
for (var i = 0; i < graph.length; i += 1) {
9999
if (current.node !== i && //if it's not the current node
100100
!visited[i] && //and if we haven't visited this node
101101
//and this node is sibling of the current...
102102
Number.isFinite(graph[i][current.node])) {
103-
103+
104104
tempDistance = current.distance + graph[i][current.node];
105105
if (tempDistance < distance[i].distance) {
106106
distance[i].distance = tempDistance;
107-
current.distance = tempDistance;
108107
unvisited.update(current);
109108
}
110109
}

0 commit comments

Comments
 (0)