You are viewing a single comment's thread. Return to all comments →
bool isBSTUtil(Node* node, int min, int max) { if (node == nullptr) return true; if (node->data <= min || node->data >= max) return false; return isBSTUtil(node->left, min, node->data) && isBSTUtil(node->right, node->data, max); }
bool checkBST(Node* root) { return isBSTUtil(root, INT_MIN, INT_MAX); }
Seems like cookies are disabled on this browser, please enable them to open this website
Is This a Binary Search Tree?
You are viewing a single comment's thread. Return to all comments →
include
bool isBSTUtil(Node* node, int min, int max) { if (node == nullptr) return true; if (node->data <= min || node->data >= max) return false; return isBSTUtil(node->left, min, node->data) && isBSTUtil(node->right, node->data, max); }
bool checkBST(Node* root) { return isBSTUtil(root, INT_MIN, INT_MAX); }