edu.princeton.cs.algs4
Class DirectedEdge
- java.lang.Object
-
- edu.princeton.cs.algs4.DirectedEdge
-
public class DirectedEdge extends java.lang.ObjectTheDirectedEdgeclass 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.
-
-
Constructor Summary
Constructors Constructor and Description DirectedEdge(int v, int w, double weight)Initializes a directed edge from vertexvto vertexwwith the givenweight.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method and Description intfrom()Returns the tail vertex of the directed edge.static voidmain(java.lang.String[] args)Unit tests theDirectedEdgedata type.intto()Returns the head vertex of the directed edge.java.lang.StringtoString()Returns a string representation of the directed edge.doubleweight()Returns the weight of the directed edge.
-
-
-
Constructor Detail
-
DirectedEdge
public DirectedEdge(int v, int w, double weight)Initializes a directed edge from vertexvto vertexwwith the givenweight.- Parameters:
v- the tail vertexw- the head vertexweight- the weight of the directed edge- Throws:
java.lang.IllegalArgumentException- if eithervorwis a negative integerjava.lang.IllegalArgumentException- ifweightisNaN
-
-
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 java.lang.String toString()
Returns a string representation of the directed edge.- Overrides:
toStringin classjava.lang.Object- Returns:
- a string representation of the directed edge
-
main
public static void main(java.lang.String[] args)
Unit tests theDirectedEdgedata type.- Parameters:
args- the command-line arguments
-
-
DataMelt 3.0 © DataMelt by jWork.ORG