Package dsa

Class DiGraph


  • public class DiGraph
    extends Object
    A data type to represent a directed graph.
    • Constructor Summary

      Constructors 
      Constructor Description
      DiGraph​(int V)
      Constructs an empty digraph with V vertices and 0 edges.
      DiGraph​(stdlib.In in)
      Constructs a digraph from the input stream in.
    • Constructor Detail

      • DiGraph

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

        public DiGraph​(stdlib.In in)
        Constructs a digraph from the input stream in.
        Parameters:
        in - the input stream.
    • Method Detail

      • V

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

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

        public void addEdge​(int v,
                            int w)
        Adds the directed edge v→w to this digraph.
        Parameters:
        v - the from vertex.
        w - the to vertex.
      • adj

        public Iterable<Integer> adj​(int v)
        Returns the vertices adjacent from vertex v in this digraph.
        Parameters:
        v - the vertex.
        Returns:
        the vertices adjacent from vertex v in this digraph.
      • outDegree

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

        public int inDegree​(int v)
        Returns the in-degree of vertex v in this digraph.
        Parameters:
        v - the vertex.
        Returns:
        the in-degree of vertex v in this digraph.
      • toString

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

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