private void dfs(Digraph G, int v) { onStack[v] = true; mark[v] = true; foreach (int w in G.adj(v)) { if (this.hasCycle()) { return; } else if (!mark[w]) { edgeTo[w] = v; dfs(G, w); } else if (onStack[w]) { cycle = new Stack <object>(); for (int x = v; x != w; x = edgeTo[x]) { cycle.push(x); } cycle.push(w); cycle.push(v); } } onStack[v] = false; }
private void dfs(Digraph G, int v) { mark[v] = true; foreach (int w in G.adj(v)) { if (!mark[w]) { dfs(G, w); } } }
private void dfs(Digraph G, int v) { pre.enqueue(v); mark[v] = true; foreach (int w in G.adj(v)) { if (!mark[w]) { dfs(G, w); } } post.enqueue(v); reversePost.push(v); }