Ejemplo n.º 1
0
        public GraphEnumerator(Graph g, TraversalStrategyEnum ts = TraversalStrategyEnum.BFS)
        {
            graph   = g ?? throw new NullReferenceException("The enumerable graph cannot be null.");
            version = g.Version;
            switch (ts)
            {
            case TraversalStrategyEnum.BFS:
            {
                strategy = new TraversalStrategyBFS(graph);
                break;
            }

            case TraversalStrategyEnum.DFS:
            {
                strategy = new TraversalStrategyDFS(graph);
                break;
            }
            }
            // if strategy's event fires, fire ours
            strategy.OnAllChildrenVisited += delegate(int nodeIndex)
            {
                OnAllChildrenVisited?.Invoke(nodeIndex);
            };
            strategy.OnHasNoChildren += delegate(int nodeIndex)
            {
                OnHasNoChildren?.Invoke(nodeIndex);
            };
        }
Ejemplo n.º 2
0
 public GraphEnumerator GetTraversalEnumerator(TraversalStrategyEnum strategy)
 {
     return(new GraphEnumerator(this, strategy));
 }