Advertisement
Guest User

Untitled

a guest
Sep 22nd, 2019
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.66 KB | None | 0 0
  1. bool isBST(Node* root) {
  2. if(root == nullptr) return true;
  3. int min = root->data;
  4. int max = root->data;
  5. return (isBSTtill(root->left, &min, &max) && isBSTtill(root->right, &min,&max));
  6.  
  7. }
  8. bool isBSTtill(Node* root, int& min, int &max)
  9. {
  10. if(root == nullptr) return true;
  11. bool l;
  12. bool r;
  13. if(root->left->data <= min)
  14. {
  15. min = root->left->data;
  16. l = isBSTtill(root->left, &min, &max);
  17. }
  18. else return false;
  19.  
  20. if(root->right->data>=max)
  21. {
  22. max = root->right->data;
  23. r = isBSTtill(root->right, &min, &max);
  24. }
  25. else return false;
  26.  
  27. return l && r;
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement