类 DirectedEdge
- java.lang.Object
-
- edu.princeton.cs.algs4.DirectedEdge
-
public class DirectedEdge extends java.lang.Object
TheDirectedEdge
class represents a weighted edge in anEdgeWeightedDigraph
. 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 directed edge and the weight.For additional documentation, see Section 4.4 of Algorithms, 4th Edition by Robert Sedgewick and Kevin Wayne.
-
-
构造器概要
构造器 构造器 说明 DirectedEdge(int v, int w, double weight)
Initializes a directed edge from vertexv
to vertexw
with the givenweight
.
-
方法概要
修饰符和类型 方法 说明 int
from()
Returns the tail vertex of the directed edge.static void
main(java.lang.String[] args)
Unit tests theDirectedEdge
data type.int
to()
Returns the head vertex of the directed edge.java.lang.String
toString()
Returns a string representation of the directed edge.double
weight()
Returns the weight of the directed edge.
-
-
-
构造器详细资料
-
DirectedEdge
public DirectedEdge(int v, int w, double weight)
Initializes a directed edge from vertexv
to vertexw
with the givenweight
.- 参数:
v
- the tail vertexw
- the head vertexweight
- the weight of the directed edge- 抛出:
java.lang.IllegalArgumentException
- if eitherv
orw
is a negative integerjava.lang.IllegalArgumentException
- ifweight
isNaN
-
-
方法详细资料
-
from
public int from()
Returns the tail vertex of the directed edge.- 返回:
- the tail vertex of the directed edge
-
to
public int to()
Returns the head vertex of the directed edge.- 返回:
- the head vertex of the directed edge
-
weight
public double weight()
Returns the weight of the directed edge.- 返回:
- the weight of the directed edge
-
toString
public java.lang.String toString()
Returns a string representation of the directed edge.- 覆盖:
toString
在类中java.lang.Object
- 返回:
- a string representation of the directed edge
-
main
public static void main(java.lang.String[] args)
Unit tests theDirectedEdge
data type.- 参数:
args
- the command-line arguments
-
-