public Digraph reverse() { Digraph rDigraph = new Digraph(V); for (int v = 0; v < V; v++) { for (int w : adj[v]) { rDigraph.addEdge(w, v); } } return rDigraph; }
public static void main(String[] args) { File tFile = new File("algs4-data//tinyDG.txt"); In in = new In(tFile); Digraph g = new Digraph(in); System.out.println(g); System.out.println(g.reverse()); }