Package dsa
Class DiEdge
java.lang.Object
dsa.DiEdge
An immutable data type to represent a weighted edge in an directed graph.
-
Constructor Summary
ConstructorDescriptionDiEdge
(int v, int w, double weight) Constructs a directed edge from vertexv
to vertexw
of the givenweight
. -
Method Summary
Modifier and TypeMethodDescriptionint
from()
Returns the tail vertex of this directed edge.static void
Unit tests the data type.int
to()
Returns the head vertex of this directed edge.toString()
Returns a string representation of this directed edge.double
weight()
Returns the weight of this directed edge.
-
Constructor Details
-
DiEdge
public DiEdge(int v, int w, double weight) Constructs a directed edge from vertexv
to vertexw
of the givenweight
.- Parameters:
v
- the tail vertex.w
- the head vertex.weight
- the weight.
-
-
Method Details
-
from
public int from()Returns the tail vertex of this directed edge.- Returns:
- the tail vertex of this directed edge.
-
to
public int to()Returns the head vertex of this directed edge.- Returns:
- the head vertex of this directed edge.
-
weight
public double weight()Returns the weight of this directed edge.- Returns:
- the weight of this directed edge
-
toString
Returns a string representation of this directed edge. -
main
Unit tests the data type.- Parameters:
args
- the command-line arguments.
-