Created
May 24, 2018 01:51
-
-
Save reyou/bc06db282748b5e252fb58d31ac6b825 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct Node | |
{ | |
int data; | |
Node *left; | |
Node *right; | |
} | |
bool IsSubtreeLesser(Node *root, int value) | |
{ | |
if(root == NULL) return true; | |
if(root->data <= value && IsSubtreeLesser(root->left, value) && IsSubtreeLesser(root->right, value)) | |
{ | |
return true; | |
} | |
else { | |
return false; | |
} | |
} | |
bool IsSubtreeGreater(Node *root, int value) | |
{ | |
if(root == NULL) return true; | |
if(root->data <= value && IsSubtreeGreater(root->left, value) && IsSubtreeGreater(root->right, value)) | |
{ | |
return true; | |
} | |
else { | |
return false; | |
} | |
} | |
bool IsBinarySearchTree(Node *root) | |
{ | |
if(root == NULL) return true; | |
if (IsSubtreeLesser(root->left, root->data) && IsSubtreeGreater(root->right, root->data) | |
&& IsBinarySearchTree(root->left) && IsBinarySearchTree(root->right)) | |
{ | |
return true; | |
} | |
else { | |
return false; | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment