Пример #1
0
        public void TraversePreorder(VisitNodeFunct visitNode, TraversalType type)
        {
            TraversalListIDS<TNode> ids=new TraversalListIDS<TNode>(type);
            TNode c;
            int i;
            Hashtable visited=new Hashtable();

            root.Parent=null;
            root.Level=0;

            ids.Add(root);

            foreach(TNode rootChild in root.Children)
                ids.Add(rootChild);

            while(ids.Count > 0)
            {
                c=ids.Get();

                if(!visited.ContainsKey(c))
                {
                    visitNode(c);
                    visited.Add(c,0);

                    i=0;
                    foreach(TNode child in c.Children)
                    {
                        child.Parent=c;
                        child.Level=c.Level+1;
                        child.ChildIndex=i;

                        ids.Add(child);
                    }
                }
            }
        }
Пример #2
0
        public void TraversePreorder(VisitNodeFunct visitNode, TraversalType type, bool delayVisit = false)
        {
            var visited = new Hashtable();

            Traverse((TNode c, TraversalListIDS<TNode> k) =>
            {
                if (type == TraversalType.DepthFirst || !visited.ContainsKey(c))
                {
                    if (delayVisit) Delay();

                    visitNode(c);

                    if (type == TraversalType.BreadthFirst)
                        visited.Add(c, (c.Level) * (c.ChildIndex + 1));

                    foreach (TNode child in c.Children)
                    {
                        k.Add(child);
                    }
                }
                return true;
            }, type);
        }