Exemple #1
0
        private static bool BruteForce(BinaryTreeNode <int> root)
        {
            if (root == null)
            {
                return(true);
            }

            foreach (BinaryTreeNode <int> node in BinaryTree.InOrderTraversal(root.Left))
            {
                if (node.Data > root.Data)
                {
                    return(false);
                }
            }

            foreach (BinaryTreeNode <int> node in BinaryTree.InOrderTraversal(root.Right))
            {
                if (node.Data < root.Data)
                {
                    return(false);
                }
            }

            return(SatisfiesBST.BruteForce(root.Left) && SatisfiesBST.BruteForce(root.Right));
        }
Exemple #2
0
        private static bool Recursive(BinaryTreeNode <int> root, int minValue = int.MinValue, int maxValue = int.MaxValue)
        {
            if (root == null)
            {
                return(true);
            }

            if (root.Data < minValue || root.Data > maxValue)
            {
                return(false);
            }

            return(SatisfiesBST.Recursive(root.Left, minValue, root.Data) && SatisfiesBST.Recursive(root.Right, root.Data, maxValue));
        }
Exemple #3
0
 private static bool Recursive(BinaryTreeNode <int> root)
 {
     return(SatisfiesBST.Recursive(root, int.MinValue, int.MaxValue));
 }