类 Edge
- java.lang.Object
-
- edu.princeton.cs.algs4.Edge
-
- 所有已实现的接口:
java.lang.Comparable<Edge>
public class Edge extends java.lang.Object implements java.lang.Comparable<Edge>
TheEdgeclass represents a weighted edge in anEdgeWeightedGraph. 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.
-
-
构造器概要
构造器 构造器 说明 Edge(int v, int w, double weight)Initializes an edge between verticesvandwof the givenweight.
-
方法概要
修饰符和类型 方法 说明 intcompareTo(Edge that)Compares two edges by weight.inteither()Returns either endpoint of this edge.static voidmain(java.lang.String[] args)Unit tests theEdgedata type.intother(int vertex)Returns the endpoint of this edge that is different from the given vertex.java.lang.StringtoString()Returns a string representation of this edge.doubleweight()Returns the weight of this edge.
-
-
-
构造器详细资料
-
Edge
public Edge(int v, int w, double weight)Initializes an edge between verticesvandwof the givenweight.- 参数:
v- one vertexw- the other vertexweight- the weight of this edge- 抛出:
java.lang.IllegalArgumentException- if eithervorwis a negative integerjava.lang.IllegalArgumentException- ifweightisNaN
-
-
方法详细资料
-
weight
public double weight()
Returns the weight of this edge.- 返回:
- the weight of this edge
-
either
public int either()
Returns either endpoint of this edge.- 返回:
- either endpoint of this edge
-
other
public int other(int vertex)
Returns the endpoint of this edge that is different from the given vertex.- 参数:
vertex- one endpoint of this edge- 返回:
- the other endpoint of this edge
- 抛出:
java.lang.IllegalArgumentException- if the vertex is not one of the endpoints of this edge
-
compareTo
public int compareTo(Edge that)
Compares two edges by weight. Note thatcompareTo()is not consistent withequals(), which uses the reference equality implementation inherited fromObject.- 指定者:
compareTo在接口中java.lang.Comparable<Edge>- 参数:
that- the other edge- 返回:
- a negative integer, zero, or positive integer depending on whether the weight of this is less than, equal to, or greater than the argument edge
-
toString
public java.lang.String toString()
Returns a string representation of this edge.- 覆盖:
toString在类中java.lang.Object- 返回:
- a string representation of this edge
-
main
public static void main(java.lang.String[] args)
Unit tests theEdgedata type.- 参数:
args- the command-line arguments
-
-