예제 #1
0
        private void Dfs(SparseGraphV2 g, int p)
        {
            Console.Write(p + ",");
            _visitedList[p] = true;
            var children = g.GetVertexes(p);

            for (int i = 0; i < children.Count; i++)
            {
                if (!_visitedList[children[i]])
                {
                    Dfs(g, children[i]);
                }
            }
        }
예제 #2
0
        private void Bfs()
        {
            if (_queue.Count == 0)
            {
                return;
            }

            int e = (int)_queue.Dequeue();

            _visitedList[e] = true;
            Console.WriteLine(e + ",");
            _graph.GetVertexes(e).ForEach(x => {
                if (!_visitedList[x] && !_queue.Contains(x))
                {
                    _queue.Enqueue(x);
                }
            });
            Bfs();
        }