Package dsa
Class Dijkstra
java.lang.Object
dsa.Dijkstra
- All Implemented Interfaces:
Paths
An immutable data type to determine the shortest paths from a fixed source vertex to every other vertex in an
edge-weighted digraph.
-
Constructor Summary
ConstructorDescriptionDijkstra
(EdgeWeightedDiGraph G, int s) Determines the shortest paths from the source vertexs
to every other vertex in the edge-weighted digraphG
. -
Method Summary
Modifier and TypeMethodDescriptiondouble
distTo
(int v) Returns the shortest distance between a designated source vertex and vertexv
, or infinity.boolean
hasPathTo
(int v) Returnstrue
if there is a path between a designated source vertex and vertex *v
, andfalse
otherwise.static void
Unit tests the data type.pathTo
(int v) Returns a path between a designated source vertex and vertexv
, ornull
.
-
Constructor Details
-
Dijkstra
Determines the shortest paths from the source vertexs
to every other vertex in the edge-weighted digraphG
.- Parameters:
G
- the edge-weighted digraph.s
- the source vertex.
-
-
Method Details
-
hasPathTo
public boolean hasPathTo(int v) Returnstrue
if there is a path between a designated source vertex and vertex *v
, andfalse
otherwise. -
pathTo
Returns a path between a designated source vertex and vertexv
, ornull
. -
distTo
public double distTo(int v) Returns the shortest distance between a designated source vertex and vertexv
, or infinity. -
main
Unit tests the data type.- Parameters:
args
- the command-line arguments.
-