Skip to content

Commit 0a677cd

Browse files
committed
Add todo for dijkstra
1 parent 432efa1 commit 0a677cd

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

src/graphs/shortest-path/dijkstra.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,17 +93,22 @@ var dijstra = function () {
9393
var tempDistance = 0;
9494
init(src, graph);
9595
while (current.node != dest && current.distance != Infinity) {
96+
var changed = false;
9697
for (var i = 0; i < graph.length; i += 1) {
9798
if (current.node !== i && //if it's not the current node
9899
!visited[i] && //and if we haven't visited this node
99100
Number.isFinite(graph[i][current.node])) { //and this node is sibling of the current...
100101

101102
tempDistance = current.distance + graph[i][current.node];
102103
if (tempDistance < distance[i].distance) {
104+
changed = true;
103105
distance[i].distance = tempDistance;
104106
}
105107
}
106108
}
109+
if (changed) {
110+
// TODO the heap should update the order of the elements!
111+
}
107112
visited[current.node] = true;
108113
current = unvisited.extract();
109114
}

0 commit comments

Comments
 (0)