Example #1
0
        private void Dfs(DiGraph G, int s)
        {
            visited[s] = true;

            foreach (var v in G.Adj(s))
            {
                if (!visited[v])
                {
                    Dfs(G, v);
                }
            }
        }
        private void BFS(DiGraph G, int source)
        {
            Queue <int> q = new Queue <int>();

            q.Enqueue(source);

            while (q.Count > 0)
            {
                var cur = q.Dequeue();

                foreach (int i in G.Adj(cur))
                {
                    q.Enqueue(i);
                }
            }
        }