You are viewing a single comment's thread. Return to all comments →
Try this
vector <int> inorder_nodes; void Traverse_Inorder(Node *root) { if(root == NULL) return; if(root->left != NULL) Traverse_Inorder(root->left); inorder_nodes.push_back(root->data); if(root->right != NULL) Traverse_Inorder(root->right); } bool checkBST(Node* root) { Traverse_Inorder(root); for (int i = 0; i < inorder_nodes.size()-1; i++){ if(inorder_nodes[i] >= inorder_nodes[i+1]) return false; } inorder_nodes.clear(); return true; }
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 →
Try this