Example #1
0
        public void TesIfABinaryTreeIsBalancedOrNot()
        {
            // create a new tree sructure
            TreeNode <int> root = new TreeNode <int>(3);

            TreesAndGraphs.Insert(root, 2);
            TreesAndGraphs.Insert(root, 1);
            TreesAndGraphs.Insert(root, 3);
            TreesAndGraphs.Insert(root, 5);
            TreesAndGraphs.Insert(root, 4);
            TreesAndGraphs.Insert(root, 6);
            List <LinkedList <TreeNode <int> > > list = new List <LinkedList <TreeNode <int> > >();
            var output = TreesAndGraphs.IsBalanced(root);
        }
Example #2
0
        public void IsBalanced()
        {
            //uses minimal tree as a helper.. (good unit tests wouldn't depend on anoter)
            int[] array  = new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 };
            var   x      = TreesAndGraphs.MinimalTree(array);
            var   result = TreesAndGraphs.IsBalanced(x);

            Assert.IsTrue(result);

            TreeNode t = new TreeNode(1);

            t.Left      = new TreeNode(2);
            t.Left.Left = new TreeNode(3);

            result = TreesAndGraphs.IsBalanced(t);
            Assert.IsFalse(result);

            t.Right = new TreeNode(4);
            result  = TreesAndGraphs.IsBalanced(t);
            Assert.IsTrue(result);
        }