I have written the following code to check if a tree is a Binary search tree. Please help me check the code:
Okay! The code is edited now. This simple solution was suggested by someone in the posts below:
IsValidBST(root,-infinity,infinity);
bool IsValidBST(BinaryNode node, int MIN, int MAX)
{
if(node == null)
return true;
if(node.element > MIN
&& node.element < MAX
&& IsValidBST(node.left,MIN,node.element)
&& IsValidBST(node.right,node.element,MAX))
return true;
else
return false;
}
right, another simple solution is do an inorder visit