コード例 #1
0
        private static Nullable <int> BalancedHeightRecursive(BinaryTreeNode <int> node)
        {
            if (node == null)
            {
                return(-1);
            }

            Nullable <int> leftHeight = IsHeightBalanced.BalancedHeightRecursive(node.Left);

            if (leftHeight == null)
            {
                return(null);
            }

            Nullable <int> rightHeight = IsHeightBalanced.BalancedHeightRecursive(node.Right);

            if (rightHeight == null)
            {
                return(null);
            }

            if (Math.Abs(rightHeight.Value - leftHeight.Value) > 1)
            {
                return(null);
            }

            return(Math.Max(rightHeight.Value, leftHeight.Value) + 1);
        }
コード例 #2
0
 private static bool Recursive(BinaryTreeNode <int> root)
 {
     return(IsHeightBalanced.BalancedHeightRecursive(root) != null);
 }