Write a function to check if a given tree is a valid binary search tree or not.
Utilisateur anonyme
A functional (but possibly slow) recursive solution: int maxInTree(Node* root) { if(root->right==NULL) return(root->data); return maxInTree(root->right); } int minInTree(Node* root) { if(root->left==NULL) return(root->data); return minInTree(root->left); } bool checkTree(Node* root) { if(root==NULL) return true; if(root->data > maxInTree(root->left)) { if(root->data right)) { if(checkTree(root->left)) { return checkTree(root->right); } } } return false; }