Accord.MachineLearning.DecisionTrees.DecisionTreeTraversal.DepthFirst C# (CSharp) Method

DepthFirst() public static method

Depth-first traversal method.
public static DepthFirst ( Accord.MachineLearning.DecisionTrees.DecisionNode tree ) : IEnumerator
tree Accord.MachineLearning.DecisionTrees.DecisionNode
return IEnumerator
        public static IEnumerator<DecisionNode> DepthFirst(DecisionNode tree)
        {
            if (tree == null)
                yield break;

            var stack = new Stack<DecisionNode>(new[] { tree });

            while (stack.Count != 0)
            {
                DecisionNode current = stack.Pop();

                yield return current;

                if (current.Branches != null)
                    for (int i = current.Branches.Count - 1; i >= 0; i--)
                        stack.Push(current.Branches[i]);
            }
        }