public class Edge extends Object implements Comparable<Edge>
EdgeWeightedGraph. Each edge consists of two integers
(naming the two vertices) and a real-value weight. The data type
provides methods for accessing the two endpoints of the edge and
the weight. The natural order for this data type is by
ascending order of weight.
For additional documentation, see Section 4.3 of Algorithms, 4th Edition by Robert Sedgewick and Kevin Wayne.
| Constructor and Description |
|---|
Edge(int v,
int w,
double weight)
Initializes an edge between vertices v/tt> and w of
the given weight.
|
| Modifier and Type | Method and Description |
|---|---|
int |
compareTo(Edge that)
Compares two edges by weight.
|
int |
either()
Returns either endpoint of the edge.
|
static void |
main(String[] args)
Unit tests the Edge data type.
|
int |
other(int vertex)
Returns the endpoint of the edge that is different from the given vertex
(unless the edge represents a self-loop in which case it returns the same vertex).
|
String |
toString()
Returns a string representation of the edge.
|
double |
weight()
Returns the weight of the edge.
|
public Edge(int v,
int w,
double weight)
IndexOutOfBoundsException - if either v or w
is a negative integerIllegalArgumentException - if weight is NaNpublic double weight()
public int either()
public int other(int vertex)
vertex - one endpoint of the edgeIllegalArgumentException - if the vertex is not one of the endpoints
of the edgepublic int compareTo(Edge that)
compareTo in interface Comparable<Edge>that - the other edgepublic String toString()
public static void main(String[] args)
Copyright © 2014. All Rights Reserved.