Пример #1
0
        /// <summary>
        /// Start a depth-first traverse of the root and all of its descendants.
        /// </summary>
        /// <param name="root">the root node point to traverse.</param>
        public void Traverse(Node root)
        {
            Node node  = root;
            int  depth = 0;

            while (node != null)
            {
                visitor.Head(node, depth);
                if (node.ChildNodeSize > 0)
                {
                    node = node.ChildNode(0);
                    depth++;
                }
                else
                {
                    while (node.NextSibling == null && depth > 0)
                    {
                        visitor.Tail(node, depth);
                        node = node.Parent;
                        depth--;
                    }
                    visitor.Tail(node, depth);
                    if (node == root)
                    {
                        break;
                    }
                    node = node.NextSibling;
                }
            }
        }