bool isBST2(TreeNode* root, int l , int r) { if (!root) return true; if (root->val > r || root->val < l) return false; if (!isBST2(root->left, l, root->val)) return false; if (!isBST2(root->right, root->val+1, r)) return false; return true; }
int isBST2(struct node* head,int min,int max){ if(!head){ return 1; } if(head->data < min || head->data > max){ return 0; } return(isBST2(head->left,min,head->data) && isBST2(head->right,head->data,max)); }
isBST2(BinaryTreeNode * pRoot, int & lowerValue) { if (pRoot==NULL) return true; if (!isBST2(pRoot->left, lowerValue)) return false; if (pRoot->nValue <= lowerValue) return false; lowerValue=pRoot->nValue; if (!isBST2(pRoot->right, lowerValue)) return false; }
main() { struct node *root = NULL; int value; root = plain_binary_tree(); printf("Initial Tree \n"); print(root); value= isBST2(root); if (value == 1) printf("Yes..It's Binary Search Tree.\n"); else printf("It's not a binary search Tree.\n"); }
bool isBst2(TreeNode* root) { return isBST2(root, INT_MIN, INT_MAX); }