Dijkstra's algorithm: Difference between revisions
→{{header|Java}}
Line 1,196:
This implementation finds the single path from a source to all reachable vertices.
Building the graph from a set of edges takes O(E log V) for each pass.
Vertices are stored in a
Decreasing the distance of a vertex is accomplished by removing it from the heap and later re-inserting it.
<lang java>
import java.io.*;
Line 1,292 ⟶ 1,290:
}
final Vertex source = graph.get(startName);
// set-up vertices
Line 1,304 ⟶ 1,302:
}
/** Implementation of dijkstra's algorithm using a
private void dijkstra(final
Vertex u, v;
while (!q.isEmpty()) {
u = q.
if (u.dist == Integer.MAX_VALUE) break; // we can ignore u (and any other remaining vertices) since they are unreachable
|