Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private static void VisitInternal<T>(T root, Func<T, IEnumerable<T>> next, Action<T> action, ICollection<T> visited = null)
- {
- if(visited == null)
- {
- visited = new HashSet<T>();
- }
- Action<T> step = node =>
- {
- action(node);
- visited.Add(node);
- VisitInternal(node, next, action, visited);
- };
- if (!visited.Contains(root))
- {
- step(root);
- }
- foreach (var parent in next(root))
- {
- if (!visited.Contains(parent))
- {
- step(parent);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement