private void Dfs(GraphList g, int v) { _visited[v] = true; foreach (var u in g.Adj(v)) { if (!_visited[u]) { _edgeTo[u] = v; Dfs(g, u); } } }
public static void DisplayGraph(GraphList g) { Console.WriteLine("{0} verticies, {1} edges", g.V(), g.E()); for (int i = 0; i < g.V(); ++i) { Console.Write("{0}: ", i); foreach (var u in g.Adj(i)) { Console.Write("{0} ", u); } Console.WriteLine(); } }
private void Bfs(GraphList g, int vertex) { Queue <int> queue = new Queue <int>(); queue.Enqueue(vertex); _visited[vertex] = true; while (queue.Count != 0) { int v = queue.Dequeue(); foreach (var u in g.Adj(v)) { if (!_visited[u]) { queue.Enqueue(u); _visited[u] = true; _edgeTo[u] = v; } } } }