Package dsa
Class Edge
- java.lang.Object
-
- dsa.Edge
-
- All Implemented Interfaces:
Comparable<Edge>
class Edge extends Object implements Comparable<Edge>
An immutable, comparable data type to represent a weighted edge in an undirected graph.
-
-
Constructor Summary
Constructors Constructor Description Edge(int v, int w, double weight)
Constructs an edge between verticesv
andw
of the given weight.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description int
compareTo(Edge other)
Returns a comparison of this edge withother
by their weights.int
either()
Returns one endpoint of this edge.static void
main(String[] args)
Unit tests the data type.int
other(int v)
Returns the endpoint of this edge that is different from vertexv
.String
toString()
Returns a string representation of this edge.double
weight()
Returns the weight of this edge.
-
-
-
Method Detail
-
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
public String toString()
Returns a string representation of this edge.
-
compareTo
public int compareTo(Edge other)
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
public static void main(String[] args)
Unit tests the data type.- Parameters:
args
- the command-line arguments.
-
-