Package dsa

Class DiEdge


  • class DiEdge
    extends Object
    An immutable data type to represent a weighted edge in an directed graph.
    • Constructor Detail

      • DiEdge

        public DiEdge​(int v,
                      int w,
                      double weight)
        Constructs a directed edge from vertex v to vertex w of the given weight.
        Parameters:
        v - the tail vertex.
        w - the head vertex.
        weight - the weight.
    • Method Detail

      • from

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

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

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

        public String toString()
        Returns a string representation of this directed edge.
        Overrides:
        toString in class Object
        Returns:
        a string representation of this directed edge.
      • main

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