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); }
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); } } }