Package dsa
Class BFSDiPaths
java.lang.Object
dsa.BFSDiPaths
- All Implemented Interfaces:
Paths
An immutable data type to compute the shortest paths from a fixed source vertex to any other vertex in a directed
graph.
-
Constructor Summary
ConstructorDescriptionBFSDiPaths
(DiGraph G, int s) Computes shortest paths from source vertexs
to every other vertex in the 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
-
BFSDiPaths
Computes shortest paths from source vertexs
to every other vertex in the digraphG
.- Parameters:
G
- the 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.
-