Is This a Binary Search Tree?

  • + 0 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); }