public DiGraph reverse() { DiGraph R = new DiGraph(V); for (int v = 0; v < V; v++) foreach (int w in Adj(v)) R.addEdge(w, v); return R; }
public DirectedDFS(DiGraph G, int s) { if (s < 0 || s > G.V - 1) { s = G.V - 1; } marked = new bool[G.V]; dfs(G, s); }
private void dfs(DiGraph G, int v) { marked[v] = true; foreach (int w in G.Adj(v)) { if (!marked[w]) { dfs(G, w); } } }
public DirectedDFS(DiGraph G, IEnumerable <int> sources) { marked = new bool[G.V]; foreach (int s in sources) { if (!marked[s]) { dfs(G, s); } } }
public DiGraph reverse() { DiGraph R = new DiGraph(V); for (int v = 0; v < V; v++) { foreach (int w in Adj(v)) { R.addEdge(w, v); } } return(R); }
private int M; // number of states public NFA(string regexp) { // Create the NFA for the given regular expression. Stack <int> ops = new Stack <int>(); re = regexp.ToCharArray(); M = re.Length; G = new DiGraph(M + 1); for (int i = 0; i < M; i++) { int lp = i; if (re[i] == '(' || re[i] == '|') { ops.Push(i); } else if (re[i] == ')') { int or = ops.Pop(); if (re[or] == '|') { lp = ops.Pop(); G.addEdge(lp, or + 1); G.addEdge(or, i); } else { lp = or; } } if (i < M - 1 && re[i + 1] == '*') // lookahead { G.addEdge(lp, i + 1); G.addEdge(i + 1, lp); } if (re[i] == '(' || re[i] == '*' || re[i] == ')') { G.addEdge(i, i + 1); } } }
private char[] re; // match transitions #endregion Fields #region Constructors public NFA(string regexp) { // Create the NFA for the given regular expression. Stack<int> ops = new Stack<int>(); re = regexp.ToCharArray(); M = re.Length; G = new DiGraph(M + 1); for (int i = 0; i < M; i++) { int lp = i; if (re[i] == '(' || re[i] == '|') ops.Push(i); else if (re[i] == ')') { int or = ops.Pop(); if (re[or] == '|') { lp = ops.Pop(); G.addEdge(lp, or + 1); G.addEdge(or, i); } else lp = or; } if (i < M - 1 && re[i + 1] == '*') // lookahead { G.addEdge(lp, i + 1); G.addEdge(i + 1, lp); } if (re[i] == '(' || re[i] == '*' || re[i] == ')') G.addEdge(i, i + 1); } }
private void dfs(DiGraph G, int v) { marked[v] = true; foreach (int w in G.Adj(v)) if (!marked[w]) dfs(G, w); }
public DirectedDFS(DiGraph G, IEnumerable<int> sources) { marked = new bool[G.V]; foreach (int s in sources) if (!marked[s]) dfs(G, s); }
public DirectedDFS(DiGraph G, int s) { if (s < 0 || s > G.V - 1) s = G.V - 1; marked = new bool[G.V]; dfs(G, s); }