예제 #1
0
        private static void PrintTree(TreeNode root)
        {
            BTreePrinter.PrintNode(root);
            var watch       = System.Diagnostics.Stopwatch.StartNew();
            var isBalanced1 = IsBalanced(root);

            watch.Stop();
            var elapsedMs = watch.ElapsedMilliseconds;

            if (isBalanced1)
            {
                Console.WriteLine("Tree is balanced");
            }
            else
            {
                Console.WriteLine("Tree is not balalnced");
            }
            Console.WriteLine($"Elapsed milliconds {elapsedMs}");

            watch = System.Diagnostics.Stopwatch.StartNew();
            var isBalanced2 = IsBalancedBook(root);

            watch.Stop();
            elapsedMs = watch.ElapsedMilliseconds;

            if (IsBalancedBook(root))
            {
                Console.WriteLine("Tree is balanced");
            }
            else
            {
                Console.WriteLine("Tree is not balalnced");
            }
            Console.WriteLine($"Elapsed milliconds {elapsedMs}");
        }
예제 #2
0
 private static void Print(TreeNode tree, TreeNode subTree)
 {
     BTreePrinter.PrintNode(tree);
     BTreePrinter.PrintNode(subTree);
     if (ContainsTree(tree, subTree))
     {
         Console.WriteLine("It is a sub tree");
     }
     else
     {
         Console.WriteLine("It is not a sub tree");
     }
 }
        private static void PrintTree(TreeNode root)
        {
            BTreePrinter.PrintNode(root);
            var isValidBST = IsValidBST(root);

            if (isValidBST)
            {
                Console.WriteLine("Tree is a valid BST");
            }
            else
            {
                Console.WriteLine("Tree is not a valid BST");
            }
        }
        public void Run()
        {
            var tree         = Q4_02_CreateMinimalBSTfromSortedUniqueArray.Create(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
            var listOfDepths = ListOfDepths(tree);

            BTreePrinter.PrintNode(tree);
            foreach (var list in listOfDepths)
            {
                foreach (var sbList in list)
                {
                    Console.Write($"{sbList.Data},");
                }
                Console.WriteLine();
            }
        }
        public void Run()
        {
            var root = Create(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);

            BTreePrinter.PrintNode(root);
        }