Пример #1
0
        public static List <UnweightedNode <T> > UnweightedDepthFirstSearch <T>(UnweightedNode <T> start)
        {
            List <UnweightedNode <T> >    nodes   = new List <UnweightedNode <T> >();
            HashSet <UnweightedNode <T> > visited = new HashSet <UnweightedNode <T> >();

            DepthFirstSearch.TraverseUnweightedDepthFirstSearch(start, nodes, visited);

            return(nodes);
        }
Пример #2
0
        private static void TraverseUnweightedDepthFirstSearch <T>(UnweightedNode <T> start, List <UnweightedNode <T> > nodes, HashSet <UnweightedNode <T> > visited)
        {
            nodes.Add(start);
            visited.Add(start);

            foreach (UnweightedNode <T> neighbor in start.GetNeighborsInOrder())
            {
                if (!visited.Contains(neighbor))
                {
                    DepthFirstSearch.TraverseUnweightedDepthFirstSearch(neighbor, nodes, visited);
                }
            }
        }