Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            TreeElement <String> root     = new TreeElement <String>("root");
            TreeElement <String> child1   = new TreeElement <String>("child1");
            TreeElement <String> child2   = new TreeElement <String>("child2");
            TreeElement <String> child11  = new TreeElement <String>("child11");
            TreeElement <String> child12  = new TreeElement <String>("child12");
            TreeElement <String> child121 = new TreeElement <String>("child121");
            TreeElement <String> child13  = new TreeElement <String>("child13");
            TreeElement <String> child21  = new TreeElement <String>("child21");

            TreeElement <int> root2 = new TreeElement <int>(0);
            TreeElement <int> int1  = new TreeElement <int>(1);
            TreeElement <int> int2  = new TreeElement <int>(2);
            TreeElement <int> int12 = new TreeElement <int>(12);

            root.addChild(child1);
            root.addChild(child2);
            child1.addChild(child11);
            child1.addChild(child12);
            child12.addChild(child121);
            child1.addChild(child13);
            child2.addChild(child21);

            root2.addChild(int1);
            root2.addChild(int2);
            int1.addChild(int12);

            root.PrintTree();
            root2.PrintTree();

            root.ForEach(TreeElement <String> .WriteNode);
            Console.WriteLine();
            child1.ForEach(TreeElement <String> .WriteNode);
            Console.WriteLine();
        }
Ejemplo n.º 2
0
 public static void WriteNode(TreeElement <T> node)
 {
     Console.Write(node.item.ToString() + " | ");
 }
Ejemplo n.º 3
0
 public void removeChild(TreeElement <T> node)
 {
     children.Remove(node);
 }
Ejemplo n.º 4
0
 public void addChild(TreeElement <T> node)
 {
     children.Add(node);
     node.parent     = this;
     node.generation = node.parent.generation + 1;
 }