예제 #1
0
        static void Main(string[] args)
        {
            var myTree = new MyTree <int>();

            //for (int i = 0; i < 10; i++)
            //{
            //    myTree.Add(i);
            //}
            myTree.Add(5);
            myTree.Add(3);
            myTree.Add(8);
            myTree.Add(7);
            myTree.Add(1);
            myTree.Add(4);
            myTree.Add(6);
            myTree.Add(9);
            myTree.Add(2);
            myTree.WriteTree();
            Console.WriteLine("==================");
            Console.WriteLine(myTree.GetTreeString());
            Console.WriteLine("==================");
            Console.WriteLine(myTree);
            Console.WriteLine("==================");
            Console.WriteLine("Preorder:");
            foreach (var item in myTree.Preorder())
            {
                Console.Write(item + " ");
            }
            Console.WriteLine("\n==================");
            Console.WriteLine("Postorder:");
            foreach (var item in myTree.Postorder())
            {
                Console.Write(item + " ");
            }
            Console.WriteLine("\n==================");
            Console.WriteLine("Inorder:");
            foreach (var item in myTree.Inorder())
            {
                Console.Write(item + " ");
            }
            Console.WriteLine("\n==================");
            Console.WriteLine("Breadthorder:");
            foreach (var item in myTree.BreadthOrder())
            {
                Console.Write(item + " ");
            }
            Console.ReadLine();
        }
        static void Main(string[] args)
        {
/*
 *            7
 *         /    \
 *        4      9
 *       / \    /  \
 *      1   6  8   10
 \
 \                    11
 */


            var tree = new MyTree();

            tree.Add(7);
            tree.Add(4);
            tree.Add(9);
            tree.Add(1);
            tree.Add(6);
            tree.Add(8);
            tree.Add(10);
            tree.Add(11);


            // var tree2 = new MyTree();
            // tree2.Add(7);
            // tree2.Add(4);
            // tree2.Add(9);
            // tree2.Add(1);
            // tree2.Add(6);
            // tree2.Add(8);
            // tree2.Add(10);

            //tree.PrintPreOrder();
            //tree.PrintInOrder();
            //tree.PrintPostOrder();
            // Console.WriteLine(tree.Height());
            // Console.WriteLine(tree.Min());
            // Console.WriteLine(tree.AreEquals(tree2));
            // Console.WriteLine(tree.ValidateBST());
            // tree.PrintNodeAtKLevel(2);
            tree.PrintAvgPerLevel();
        }