Exemple #1
0
        public static bool IsValid(TreeNode <int> node, int min, int max)
        {
            if (node == null)
            {
                return(true);
            }

            if (node.Value > max || node.Value <= min)
            {
                return(false);
            }

            if (node.Left != null)
            {
                if (!BinarySearchTreeValidator.IsValid(node.Left, min, node.Value))
                {
                    return(false);
                }
            }

            if (node.Right != null)
            {
                if (!BinarySearchTreeValidator.IsValid(node.Right, node.Value, max))
                {
                    return(false);
                }
            }

            return(true);
        }
Exemple #2
0
 public static bool IsValid(TreeNode <int> head)
 {
     return(BinarySearchTreeValidator.IsValid(head, int.MinValue, int.MaxValue));
 }