public void Print(TextWriter writer) { BFS bfs = new BFS(G); for (int i = 0; i < G.V; i++) { List<int> connected = new List<int>(); if (bfs.VertexState[i] == BFS.State.Undiscovered) { bfs.Traverse(i, (g, v, e) => { }, (g, v) => { connected.Add(v); } ); } writer.WriteLine(String.Join(" ", connected)); } }
public static void PrintDot(Graph graph, TextWriter writer) { GraphTraversal traversal = new BFS(graph); writer.WriteLine("{0} {1} {{", graph.IsDirected ? "digraph" : "graph", graph.GetHashCode()); for (int i = 0; i < graph.V; i++) { traversal.Traverse(i, (G, V, E) => { writer.WriteLine("{0} {1} {2};", V, G.IsDirected ? "->" : "--", E.Y); }, (G, V) => { writer.WriteLine("{0};", V); }); } writer.WriteLine("}"); }