Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- bool isBST(Node* root) {
- if(root == nullptr) return true;
- int min = root->data;
- int max = root->data;
- return (isBSTtill(root->left, &min, &max) && isBSTtill(root->right, &min,&max));
- }
- bool isBSTtill(Node* root, int& min, int &max)
- {
- if(root == nullptr) return true;
- bool l;
- bool r;
- if(root->left->data <= min)
- {
- min = root->left->data;
- l = isBSTtill(root->left, &min, &max);
- }
- else return false;
- if(root->right->data>=max)
- {
- max = root->right->data;
- r = isBSTtill(root->right, &min, &max);
- }
- else return false;
- return l && r;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement