Package dsa
Class Edge
java.lang.Object
dsa.Edge
- All Implemented Interfaces:
Comparable<Edge>
An immutable, comparable data type to represent a weighted edge in an undirected graph.
-
Constructor Summary
ConstructorDescriptionEdge
(int v, int w, double weight) Constructs an edge between verticesv
andw
of the given weight. -
Method Summary
Modifier and TypeMethodDescriptionint
Returns a comparison of this edge withother
by their weights.int
either()
Returns one endpoint of this edge.static void
Unit tests the data type.int
other
(int v) Returns the endpoint of this edge that is different from vertexv
.toString()
Returns a string representation of this edge.double
weight()
Returns the weight of this edge.
-
Constructor Details
-
Edge
public Edge(int v, int w, double weight) Constructs an edge between verticesv
andw
of the given weight.- Parameters:
v
- one vertex.w
- the other vertex.weight
- the weight.
-
-
Method Details
-
either
public int either()Returns one endpoint of this edge.- Returns:
- one endpoint of this edge
-
other
public int other(int v) Returns the endpoint of this edge that is different from vertexv
.- Parameters:
v
- one endpoint of this edge- Returns:
- the endpoint of this edge that is different from vertex
v
.
-
weight
public double weight()Returns the weight of this edge.- Returns:
- the weight of this edge.
-
toString
Returns a string representation of this edge. -
compareTo
Returns a comparison of this edge withother
by their weights.- Specified by:
compareTo
in interfaceComparable<Edge>
- Parameters:
other
- the other edge.- Returns:
- a comparison of this edge with
other
by their weights.
-
main
Unit tests the data type.- Parameters:
args
- the command-line arguments.
-