Example #1
0
        private void CreateBinaryTree()
        {
            try
            {
                //BinaryTree<int> tree = new BinaryTree<int>(new BinaryTreeNode<int>(1));
                //tree.Root.Left = new BinaryTreeNode<int>(2);
                //tree.Root.Right = new BinaryTreeNode<int>(3);
                //tree.Root.Left.Left = new BinaryTreeNode<int>(4);
                //tree.Root.Right.Right = new BinaryTreeNode<int>(5);
                //tree.Root.Left.Left.Right = new BinaryTreeNode<int>(6);
                //tree.Root.Right.Right.Right = new BinaryTreeNode<int>(7);
                //tree.Root.Right.Right.Right.Right = new BinaryTreeNode<int>(8);

                /*
                 *              1
                 *            2   3
                 *           4      5
                 *             6     7
                 *                    8
                 */

                //tree.Print(tree.Root, Enumerations.PrintTreeMode.BinaryInfix);

                //BinarySearchTree<int> tree = new BinarySearchTree<int>(new BinaryTreeNode<int>(5));
                //tree.Add(4);
                //tree.Add(2);
                //tree.Add(3);
                //tree.Add(1);
                //tree.Add(7);
                //tree.Add(6);
                //tree.Add(8);
                ///*
                //                5
                //              4   7
                //             2   6 8
                //            1 3
                //*/

                //tree.Print(tree.Root, Enumerations.PrintTreeMode.BinaryInfix);

                //BinarySearchTree<int> tree = new BinarySearchTree<int>();
                //for (int i = 0; i < 100; i++)
                //    tree.Add(i);
                //tree.Print(tree.Root, Enumerations.PrintTreeMode.BinaryInfix);

                //BinarySearchTree<int> tree = new BinarySearchTree<int>(new BinaryTreeNode<int>(5));
                //tree.Add(4);
                //tree.Add(2);
                //tree.Add(3);
                //tree.Add(1);
                //tree.Add(6);
                //tree.Add(7);
                //tree.Add(8);
                ///*
                //                5
                //              4   6
                //             2     7
                //            1 3     8
                //*/

                //tree.Print(tree.Root, Enumerations.PrintTreeMode.ZigZagStartLeft);
                //tree.Print(tree.Root, Enumerations.PrintTreeMode.ZigZagStartRight);


                //AVLTree<int> tree = new AVLTree<int>(new BinaryTreeNode<int>(10));
                //tree.Add(30);
                ///*
                //                10
                //                  30
                //*/
                //tree.Print(tree.Root, Enumerations.PrintTreeMode.LeftToRight);
                //Console.WriteLine();
                //tree.Add(20);
                ///*
                //                20
                //             10    30
                //*/
                //tree.Print(tree.Root, Enumerations.PrintTreeMode.LeftToRight);
                //Console.WriteLine();
                //tree.Add(40);
                ///*
                //                20
                //             10    30
                //                      40
                //*/
                //tree.Print(tree.Root, Enumerations.PrintTreeMode.LeftToRight);
                //Console.WriteLine();
                //tree.Add(50);
                ///*
                //                 20
                //             10      40
                //                  30    50
                //*/

                //tree.Print(tree.Root, Enumerations.PrintTreeMode.LeftToRight);

                AVLTree <double> tree = new AVLTree <double>();
                for (int i = 1; i <= 15; i++)
                {
                    tree.Add(i);
                }
                for (int i = 0; i <= 15; i++)
                {
                    tree.Add(0.5 + i);
                }
                Console.WriteLine(tree.Print(tree.Root, Enumerations.PrintTreeMode.BinaryPrefix));


                // see how much faster iterative print is..

                //System.Diagnostics.Stopwatch sw = System.Diagnostics.Stopwatch.StartNew();
                //for (int i = 0; i < 100; i++)
                //{
                //    System.Collections.Generic.Stack<TreeNode<double>> s = new System.Collections.Generic.Stack<TreeNode<double>>();
                //    s.Push(tree.Root);
                //    tree.PrintZigZagToString(s, new System.Collections.Generic.Stack<TreeNode<double>>(), 0);
                //}
                //sw.Stop();
                //Console.WriteLine(string.Format("Time: {0}", sw.ElapsedTicks));

                //sw = System.Diagnostics.Stopwatch.StartNew();
                //for (int i = 0; i < 100; i++)
                //    tree.PrintZigZag_Iterative(Enumerations.PrintTreeMode.ZigZagStartLeft);
                //sw.Stop();
                //Console.WriteLine(string.Format("Time: {0}", sw.ElapsedTicks));
            }
            catch (Exception ex) { MsgBox.Show(ex.Message); }
        }
Example #2
0
        public MainWindow()
        {
            InitializeComponent();

            avl_tree = new AVLTree <double>();
        }