Skip to content

Commit 5ca8a0a

Browse files
committed
Merge pull request algorithm-visualizer#103 from TornjV/fix/dijkstra-visualization
Fix visualization
2 parents 828a9f0 + cc654b5 commit 5ca8a0a

File tree

1 file changed

+2
-3
lines changed
  • algorithm/graph_search/dijkstra/shortest_path

1 file changed

+2
-3
lines changed

algorithm/graph_search/dijkstra/shortest_path/code.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,20 @@ function Dijkstra(start, end) {
33
var D = []; // D[i] indicates whether the i-th node is discovered or not
44
for (var i = 0; i < G.length; i++) D.push(false);
55
S[start] = 0; // Starting node is at distance 0 from itself
6+
tracerS._notify(start, S[start]);
67
var k = G.length;
78
while (k--) {
89
// Finding a node with the shortest distance from S[minIndex]
910
minDistance = MAX_VALUE;
1011
for (i = 0; i < G.length; i++) {
11-
tracerS._select(i)._wait();
1212
if (S[i] < minDistance && !D[i]) {
1313
minDistance = S[i];
1414
minIndex = i;
1515
}
16-
tracerS._deselect(i);
1716
}
1817
if (minDistance == MAX_VALUE) break; // If there is no edge from current node, jump out of loop
1918
D[minIndex] = true;
20-
tracerS._notify(minIndex, S[minIndex])._denotify(minIndex);
19+
tracerS._notify(minIndex);
2120
tracer._visit(minIndex)._wait();
2221
// For every unvisited neighbour of current node, we check
2322
// whether the path to it is shorter if going over the current node

0 commit comments

Comments
 (0)