Package dsa

Class EdgeWeightedDiGraph

java.lang.Object
dsa.EdgeWeightedDiGraph

public class EdgeWeightedDiGraph extends Object
A data type to represent a directed graph with weighted edges.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Constructs an empty edge-weighted digraph with V vertices and 0 edges.
    EdgeWeightedDiGraph(stdlib.In in)
    Constructs an edge-weighted digraph from the input stream in.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Adds a directed edge e to this edge-weighted digraph.
    adj(int v)
    Returns the directed edges incident from vertex v in this edge-weighted digraph.
    int
    E()
    Returns the number of edges in this edge-weighted digraph.
    Returns all the directed edges in this edge-weighted digraph.
    int
    inDegree(int v)
    Returns the in-degree of vertex v in this edge-weighted digraph.
    static void
    main(String[] args)
    Unit tests the data type.
    int
    outDegree(int v)
    Returns the out-degree of vertex v in this edge-weighted digraph.
    Returns a string representation of this edge-weighted digraph.
    int
    V()
    Returns the number of vertices in this edge-weighted digraph.

    Methods inherited from class java.lang.Object

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

    • EdgeWeightedDiGraph

      public EdgeWeightedDiGraph(int V)
      Constructs an empty edge-weighted digraph with V vertices and 0 edges.
      Parameters:
      V - number of vertices.
    • EdgeWeightedDiGraph

      public EdgeWeightedDiGraph(stdlib.In in)
      Constructs an edge-weighted digraph from the input stream in.
      Parameters:
      in - the input stream.
  • Method Details

    • V

      public int V()
      Returns the number of vertices in this edge-weighted digraph.
      Returns:
      the number of vertices in this edge-weighted digraph.
    • E

      public int E()
      Returns the number of edges in this edge-weighted digraph.
      Returns:
      the number of edges in this edge-weighted digraph.
    • addEdge

      public void addEdge(DiEdge e)
      Adds a directed edge e to this edge-weighted digraph.
      Parameters:
      e - the directed edge.
    • adj

      public Iterable<DiEdge> adj(int v)
      Returns the directed edges incident from vertex v in this edge-weighted digraph.
      Parameters:
      v - the vertex.
      Returns:
      the directed edges incident from vertex v in this edge-weighted digraph.
    • outDegree

      public int outDegree(int v)
      Returns the out-degree of vertex v in this edge-weighted digraph.
      Parameters:
      v - the vertex.
      Returns:
      the out-degree of vertex v in this edge-weighted digraph.
    • inDegree

      public int inDegree(int v)
      Returns the in-degree of vertex v in this edge-weighted digraph.
      Parameters:
      v - the vertex.
      Returns:
      the in-degree of vertex v in this edge-weighted digraph.
    • edges

      public Iterable<DiEdge> edges()
      Returns all the directed edges in this edge-weighted digraph.
      Returns:
      all the directed edges in this edge-weighted digraph.
    • toString

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

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