Class Digraph

Object
  extended by Digraph

public class Digraph
extends Object

The Digraph class represents an directed graph of vertices named 0 through V-1. It supports the following operations: add an edge to the graph, iterate over all of the neighbors incident to a vertex. Parallel edges and self-loops are permitted.

For additional documentation, see Section 4.2 of Algorithms, 4th Edition by Robert Sedgewick and Kevin Wayne.


Constructor Summary
Digraph(Digraph G)
          Copy constructor.
Digraph(In in)
          Create a digraph from input stream.
Digraph(int V)
          Create an empty digraph with V vertices.
 
Method Summary
 void addEdge(int v, int w)
          Add the directed edge v-w to the digraph.
 Iterable<Integer> adj(int v)
          Return the list of neighbors of vertex v as in Iterable.
 int E()
          Return the number of edges in the digraph.
static void main(String[] args)
          Test client.
 Digraph reverse()
          Return the reverse of the digraph.
 String toString()
          Return a string representation of the digraph.
 int V()
          Return the number of vertices in the digraph.
 
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Digraph

public Digraph(int V)
Create an empty digraph with V vertices.


Digraph

public Digraph(In in)
Create a digraph from input stream.


Digraph

public Digraph(Digraph G)
Copy constructor.

Method Detail

V

public int V()
Return the number of vertices in the digraph.


E

public int E()
Return the number of edges in the digraph.


addEdge

public void addEdge(int v,
                    int w)
Add the directed edge v-w to the digraph.


adj

public Iterable<Integer> adj(int v)
Return the list of neighbors of vertex v as in Iterable.


reverse

public Digraph reverse()
Return the reverse of the digraph.


toString

public String toString()
Return a string representation of the digraph.

Overrides:
toString in class Object

main

public static void main(String[] args)
Test client.