Package edu.princeton.cs.algs4
Class DirectedEdge
 Object

 edu.princeton.cs.algs4.DirectedEdge

public class DirectedEdge extends Object
TheDirectedEdge
class represents a weighted edge in anEdgeWeightedDigraph
. Each edge consists of two integers (naming the two vertices) and a realvalue 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.
 Author:
 Robert Sedgewick, Kevin Wayne


Constructor Summary
Constructors Constructor Description DirectedEdge(int v, int w, double weight)
Initializes a directed edge from vertexv
to vertexw
with the givenweight
.

Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description int
from()
Returns the tail vertex of the directed edge.static void
main(String[] args)
Unit tests theDirectedEdge
data type.int
to()
Returns the head vertex of the directed edge.String
toString()
Returns a string representation of the directed edge.double
weight()
Returns the weight of the directed edge.



Constructor Detail

DirectedEdge
public DirectedEdge(int v, int w, double weight)
Initializes a directed edge from vertexv
to vertexw
with the givenweight
. Parameters:
v
 the tail vertexw
 the head vertexweight
 the weight of the directed edge Throws:
IllegalArgumentException
 if eitherv
orw
is a negative integerIllegalArgumentException
 ifweight
isNaN


Method Detail

from
public int from()
Returns the tail vertex of the directed edge. Returns:
 the tail vertex of the directed edge

to
public int to()
Returns the head vertex of the directed edge. Returns:
 the head vertex of the directed edge

weight
public double weight()
Returns the weight of the directed edge. Returns:
 the weight of the directed edge

toString
public String toString()
Returns a string representation of the directed edge.

main
public static void main(String[] args)
Unit tests theDirectedEdge
data type. Parameters:
args
 the commandline arguments

