Advertisement
Guest User

Untitled

a guest
Jun 24th, 2017
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.60 KB | None | 0 0
  1.         private static void VisitInternal<T>(T root, Func<T, IEnumerable<T>> next, Action<T> action, ICollection<T> visited = null)
  2.         {
  3.             if(visited == null)
  4.             {
  5.                 visited = new HashSet<T>();
  6.             }
  7.  
  8.             Action<T> step = node =>
  9.                              {
  10.                                 action(node);
  11.                                 visited.Add(node);
  12.                                 VisitInternal(node, next, action, visited);
  13.                              };
  14.  
  15.             if (!visited.Contains(root))
  16.             {
  17.                 step(root);
  18.             }
  19.            
  20.             foreach (var parent in next(root))
  21.             {
  22.                 if (!visited.Contains(parent))
  23.                 {
  24.                     step(parent);
  25.                 }
  26.             }
  27.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement