public DepthFirstDirectedPath(Digraph g, int s) { marked = new bool[g.V()]; edgeTo = new int[g.V()]; this.s = s; dfs(g, s); }
public BreadthFirstDirectedPaths(Digraph graph, int s) { marked = new bool[graph.V()]; edgeTo = new int[graph.V()]; this.s = s; bfs(graph, s); }
public DirectedCycle(Digraph g) { onStack = new bool[g.V()]; edgeTo = new int[g.V()]; marked = new bool[g.V()]; for (int v = 0; v < g.V(); v++) { if (!marked[v]) dfs(g, v); } }
public DirectDfs(Digraph graph, IEnumerable<int> sources) { marked = new bool[graph.V()]; for (int i = 0; i < sources.Count(); i++) { if (!marked[i]) { dfs(graph, i); } } }
public void MarkedTest() { var graph = new Digraph(13, 22, new[] { "4 2", "2 3", "3 2", "6 0", "0 1", "2 0", "11 12", "12 9", "9 10", "9 11", "8 9", "10 12", "11 4", "4 3", "3 5", "7 8", "8 7", "5 4", "0 5", "6 4", "6 9", "7 6" }); int[] sources = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13 }; var reachable = new DirectDfs(graph, sources); StringBuilder builder = new StringBuilder(); for (int v = 0; v < graph.V(); v++) { if (reachable.Marked(v)) { builder.AppendLine(v + " "); } } }
public DirectDfs(Digraph graph, int s) { marked = new bool[graph.V()]; dfs(graph, s); }