예제 #1
0
        void dfs(int vertex, ICollection <int> items, bool[] marked, GraphBase graph)
        {
            if (marked[vertex])
            {
                return;
            }

            marked[vertex] = true;
            items.Add(vertex);

            foreach (var w in graph.GetVertexAdjcency(vertex))
            {
                if (!marked[w])
                {
                    dfs(w, items, marked, graph);
                    _EdgeTo[w] = vertex;
                }
            }
        }
        void bfs(int startVertex, ICollection <int> items, bool[] marked, GraphBase graph)
        {
            var queue = new Queue <int>();

            queue.Enqueue(startVertex);
            items.Add(startVertex);
            marked[startVertex] = true;

            while (queue.Count > 0)
            {
                var vertex = queue.Dequeue();
                foreach (var w in graph.GetVertexAdjcency(vertex))
                {
                    if (!marked[w])
                    {
                        marked[w] = true;
                        items.Add(w);
                        _EdgeTo[w] = vertex;
                        queue.Enqueue(w);
                    }
                }
            }
        }