Package dsa

Class DiEdge

java.lang.Object
dsa.DiEdge

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

    Constructors
    Constructor
    Description
    DiEdge(int v, int w, double weight)
    Constructs a directed edge from vertex v to vertex w of the given weight.
  • Method Summary

    Modifier and Type
    Method
    Description
    int
    Returns the tail vertex of this directed edge.
    static void
    main(String[] args)
    Unit tests the data type.
    int
    to()
    Returns the head vertex of this directed edge.
    Returns a string representation of this directed edge.
    double
    Returns the weight of this directed edge.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • 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 Details

    • 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.