Пример #1
0
 public DirectedDFS(DiGraph G, IEnumerable <int> Sources)
 {
     visited = new bool[G.Vertices()];
     foreach (var source in Sources)
     {
         Dfs(G, source);
     }
 }
Пример #2
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);
                }
            }
        }
 public DirectedBfs(DiGraph G, int source)
 {
     BFS(G, source);
 }
Пример #5
0
        private bool[] visited;     // visitd[v] = true if v is reachable from source

        public DirectedDFS(DiGraph G, int source)
        {
            visited = new bool[G.Vertices()];
            Dfs(G, source);
        }