/** * Initializes a new digraph that is a deep copy of the specified digraph. 拷贝构造 * * @param G the digraph to copy */ public Digraph(Digraph G) { this(G.V()); this.E = G.E(); for (int v = 0; v < V; v++) this.indegree[v] = G.indegree(v); for (int v = 0; v < G.V(); v++) { // reverse so that adjacency list is in same order as original // 保证原序 Stack<Integer> reverse = new Stack<Integer>(); for (int w : G.adj[v]) { reverse.push(w); } for (int w : reverse) { adj[v].add(w); } } }