Exemple #1
0
        static void CallTheTree()
        {
            BinaryTree <int> integerTree = new BinaryTree <int>();

            Random rand = new Random();

            for (int i = 0; i < 20; i++)
            {
                int value = rand.Next(100);
                Console.WriteLine("Adding {0}", value);
                integerTree.Add(value);
            }

            Console.WriteLine("Number of nodes is {0}", integerTree.Count);
            Console.WriteLine("Max value is {0}", integerTree.MaxValue);
            Console.WriteLine("Min value is {0}", integerTree.MinValue);
            Console.WriteLine("Preorder traversal:");
            Console.WriteLine(string.Join(" ", integerTree.Preorder()));
            Console.WriteLine("Inorder traversal:");
            Console.WriteLine(string.Join(" ", integerTree.Inorder()));
            Console.WriteLine("Postorder traversal:");
            Console.WriteLine(string.Join(" ", integerTree.Postorder()));
            Console.WriteLine("Levelorder traversal:");
            Console.WriteLine(string.Join(" ", integerTree.Levelorder()));
            Console.WriteLine("Default traversal (inorder):");
            foreach (int n in integerTree)
            {
                Console.Write("{0} ", n);
            }
            Console.WriteLine();
            Console.ReadKey(true);
        }
Exemple #2
0
        static void Main(string[] args)
        {
            BinaryTree b = new BinaryTree();

            b.insert(8);
            b.insert(10);
            b.insert(10);
            //b.insert(15);
            //b.insert(11);
            //b.insert(9);
            //b.insert(26);
            b.insert(4);
            //b.insert(6);
            //b.insert(2);
            //b.insert(2);

            b.Inorder();
            b.Postorder();
            //Console.WriteLine(b.Min());
            //Console.WriteLine(b.Max());
            b.Delete(99);

            b.Inorder();
        }