Class DirectedEdge


  • public class DirectedEdge
    extends Object
    The DirectedEdge class represents a weighted edge in an EdgeWeightedDigraph. 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.

    Author:
    Robert Sedgewick, Kevin Wayne
    • Constructor Detail

      • DirectedEdge

        public DirectedEdge​(int v,
                            int w,
                            double weight)
        Initializes a directed edge from vertex v to vertex w with the given weight.
        Parameters:
        v - the tail vertex
        w - the head vertex
        weight - the weight of the directed edge
        Throws:
        IllegalArgumentException - if either v or w is a negative integer
        IllegalArgumentException - if weight is NaN
    • 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.
        Overrides:
        toString in class Object
        Returns:
        a string representation of the directed edge
      • main

        public static void main​(String[] args)
        Unit tests the DirectedEdge data type.
        Parameters:
        args - the command-line arguments