public void IsBalancedTests() { BalancedBinaryTree obj = new BalancedBinaryTree(); var t = new TreeNode(3) { left = new TreeNode(9), right = new TreeNode(20) { left = new TreeNode(15), right = new TreeNode(7) } }; var x = obj.IsBalanced(t); t = new TreeNode(1) { left = new TreeNode(2) { left = new TreeNode(3) { left = new TreeNode(4), right = new TreeNode(4) }, right = new TreeNode(3) }, right = new TreeNode(2) }; x = obj.IsBalanced(t); }
public static void Main() { TrippleSum.Do(); ConnectNodesAtTheSameLevel.Do(); JumpingNumbers.Do(); LongestValidSubstring.Do(); SizeOfSubarrayWithMaximumSum.Do(); SubarrayWithSumNonNegative.Do(); SubArrayWithNegativeSum.Do(); SmallestPositiveInteger.Do(); CommonAncestor.Do(); BinaryTreeIsBST.Do(); BalancedBinaryTree.Do(); ReverseList.Do(); SumToGivenValue.Do(); Rectangle.Do(); Parentheses.Do(); FindTripplets.Do(); SubTree.Do(); NumberOfIntInArray.Do(); MinimumArrayOfSumGreater.Do(); ReplaceNumbers.Do(); SubArrayWithSum.Do(); SmallestPositiveInteger.Do(); }
public void GetZigZag_EmptyTree_ReturnsEmptyList() { BalancedBinaryTree tree = new BalancedBinaryTree(); List <BinaryTreeNode> nodes = tree.GetZigZag(); Assert.IsTrue(nodes.Count == 0); }
public void IsBalancedTreeTests(object[] treeNodes, bool expectedBalanced) { // arrange var root = TreeNode.Build(treeNodes); // act bool isBalanced = BalancedBinaryTree.IsBalancedBinaryTree(root); // assert Assert.AreEqual(expectedBalanced, isBalanced); }
public void IsBalancedTest() { // balanced tree TreeNode root = new TreeNode(3); root.left = new TreeNode(9); root.right = new TreeNode(20); root.right.left = new TreeNode(15); root.right.right = new TreeNode(7); bool expected = true; bool isBalanced = new BalancedBinaryTree().IsBalanced(root); Assert.AreEqual(expected, isBalanced); }
public void GetZigZag_TreeWith6Nodes_Returns6NodesInZigZagOrder() { BalancedBinaryTree tree = new BalancedBinaryTree(); tree.Root = new BinaryTreeNode(4); tree.Insert(tree.Root, 2); tree.Insert(tree.Root, 6); tree.Insert(tree.Root, 1); tree.Insert(tree.Root, 5); tree.Insert(tree.Root, 7); tree.Insert(tree.Root, 3); List <BinaryTreeNode> nodes = tree.GetZigZag(); Assert.IsTrue(nodes.Count == 6); }