예제 #1
0
        static void Main(string[] args)
        {
            Tree theTree = new Tree();

            theTree.Insert(20);
            theTree.Insert(25);
            theTree.Insert(45);
            theTree.Insert(15);
            theTree.Insert(67);
            theTree.Insert(43);
            theTree.Insert(80);
            theTree.Insert(33);
            theTree.Insert(67);
            theTree.Insert(99);
            theTree.Insert(91);
            Console.WriteLine("Inorder Traversal : ");
            theTree.Inorder(theTree.ReturnRoot());
            Console.WriteLine(" ");
            Console.WriteLine();
            Console.WriteLine("Preorder Traversal : ");
            theTree.Preorder(theTree.ReturnRoot());
            Console.WriteLine(" ");
            Console.WriteLine();
            Console.WriteLine("Postorder Traversal : ");
            theTree.Postorder(theTree.ReturnRoot());
            Console.WriteLine(" ");
            Console.ReadLine();
        }
예제 #2
0
        public void traverse_tree_in_inorder_manner()
        {
            List <int> result = new List <int>();
            Tree       tree   = new Tree(10);

            tree.Insert(5);
            tree.Insert(15);
            tree.Insert(1);
            tree.Insert(6);

            tree.Inorder(x =>
            {
                result.Add(x);
            });

            Assert.Equal(5, result.Count);
            Assert.Equal(1, result[0]);
            Assert.Equal(5, result[1]);
            Assert.Equal(6, result[2]);
            Assert.Equal(10, result[3]);
            Assert.Equal(15, result[4]);
        }