SHARE
TWEET

Untitled

a guest Sep 22nd, 2019 76 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top