Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Hidden stub code will pass a root argument to the function below. Complete the function to solve the challenge. Hint: you may want to write one or more helper functions.
- The Node struct is defined as follows:
- struct Node {
- int data;
- Node* left;
- Node* right;
- }
- */
- bool left(Node *root , int n){
- if(root == NULL){
- return 1;
- }else if(root->data >= n){
- return 0;
- }else{
- return left(root->left , root->data)
- && left(root->left , n)
- && left(root->right , n)
- && right(root->right, root->data);
- }
- }
- bool right (Node *root , int n){
- if(root == NULL){
- return 1;
- }else if(root->data <= n){
- return 0;
- }else{
- return right(root->right , root->data)
- && right(root->right, n)
- && right(root->left , n)
- && left(root->left , root->data);
- }
- }
- bool checkBST(Node * root) {
- if(root == NULL) return true;
- return right(root->right , root->data) && left(root->left , root->data);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement