Пример #1
0
 public static void Traverse(NTree <T> node, TreeVisitor <T> visitor)
 {
     visitor(node.data);
     foreach (NTree <T> kid in node.children)
     {
         Traverse(kid, visitor);
     }
 }
Пример #2
0
 public static void Traverse(NTree <T> node, Action startAct, TreeVisitor <T> visitor, Action endAct)
 {
     startAct();
     visitor(node.data);
     foreach (NTree <T> kid in node.children)
     {
         Traverse(kid, startAct, visitor, endAct);
     }
     endAct();
 }
Пример #3
0
        public NTree <T> Clone()
        {
            var tree = new NTree <T>(this.data);

            foreach (var child in this.children)
            {
                tree.AddChild(child);
            }
            return(tree);
        }
Пример #4
0
        public static NTree <T> CreateTree <T>(NTree <T> tree, params T[] children)
        {
            var clone = tree.Clone();

            foreach (var child in children)
            {
                clone.AddChild(child);
            }

            return(clone);
        }
Пример #5
0
        public static NTree <T> CreateTree <T>(T root, params NTree <T>[] children)
        {
            var tree = new NTree <T>(root);

            foreach (var child in children)
            {
                tree.AddChild(child);
            }

            return(tree);
        }
Пример #6
0
        public static NTree <T> CreateTree <T>(NTree <T> root, params NTree <T>[] children)
        {
            var clone = root.Clone();

            foreach (var child in children)
            {
                clone.AddChild(child);
            }

            return(clone);
        }
Пример #7
0
 public void AddChild(NTree <T> data)
 {
     children.AddFirst(data.Clone());
 }