Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions algorithm/graph_search/dijkstra/shortest_path/code.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,20 @@ function Dijkstra(start, end) {
var D = []; // D[i] indicates whether the i-th node is discovered or not
for (var i = 0; i < G.length; i++) D.push(false);
S[start] = 0; // Starting node is at distance 0 from itself
tracerS._notify(start, S[start]);
var k = G.length;
while (k--) {
// Finding a node with the shortest distance from S[minIndex]
minDistance = MAX_VALUE;
for (i = 0; i < G.length; i++) {
tracerS._select(i)._wait();
if (S[i] < minDistance && !D[i]) {
minDistance = S[i];
minIndex = i;
}
tracerS._deselect(i);
}
if (minDistance == MAX_VALUE) break; // If there is no edge from current node, jump out of loop
D[minIndex] = true;
tracerS._notify(minIndex, S[minIndex])._denotify(minIndex);
tracerS._notify(minIndex);
tracer._visit(minIndex)._wait();
// For every unvisited neighbour of current node, we check
// whether the path to it is shorter if going over the current node
Expand Down