Friday, May 24, 2013

Check if a binary tree is BST or not

bool BinaryTree::isBST(Node* node)

{
static Node* prev = 0;
if(node)
{
if(!isBST(node->left))
return false;
if(prev && node->data <= prev->data)
return false;
prev = node;
return isBST(node->right);
}
return true;
}

No comments:

Post a Comment