Ejemplo n.º 1
0
        static void Main(String[] args)
        {
            try
            {
                //   var s = string.Split("");
                // Regex.Split(source, @"(?<!^)(?=[A-Z])");
                //  Console.ReadLine();
                //var buff = Regex.Matches(input, @"(.)\1");
                SortingAlgorithms.QuickSortMethod();
                BinarySearchTree b = new BinarySearchTree(8);
                b.Insert(4);
                b.Insert(9);
                b.Insert(1);
                b.Insert(2);
                b.Insert(3);
                b.Insert(6);
                b.Insert(5);
                var list = LevelOrder(b.Root);

                var lcaNode  = TreeAlgorithms.LeastCommonAncestry(b.Root, 1, 2);
                var Distance = TreeAlgorithms.GetDistance(b.Root, 3);
                System.Console.WriteLine(string.Format("LCA : {0}\nDistance: {1}", lcaNode.Data, Distance));
                System.Console.ReadLine();

                int[] inOrder  = { 4, 2, 5, 1, 3 };
                int[] preOrder = { 1, 2, 4, 5, 3 };
                int   len      = inOrder.Count() - 1;
                var   tree     = BinarySearchTree.BuildTree(inOrder, preOrder, 0, len);

                Display(tree);
                System.Console.WriteLine("Press any key...");
                var name = System.Console.ReadLine();
            }
            catch (Exception ex)
            {
                System.Console.Write(ex.Message + ex.StackTrace);
                System.Console.WriteLine("Press any key...");
                var name = System.Console.ReadLine();
            }
        }