Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // returns -1 if it is not bst, otherwise it is bst
- int ifBST(BSTnode * root){
- odp o;
- o.ok=true;
- if(root == NULL){
- return 0;
- }
- else{
- int leftHeight = ifBST(root->left) , rightHeight = ifBST(root->right);
- if(leftHeight == -1 || rightHeight == -1 || abs(rightHeight - leftHeight)>1){
- return -1;
- }
- return 1 + max(leftHeight, rightHeight);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement