If anyone can tell me where I am going wrong with this method, that would be reaallly awesome, because I have no idea how to make hte method work properly. It consists of two methods actually, a driver method for the recursive method, and the recursive method itself:
public boolean isBST(tNode r) // r is the root of the tree passed in on calling this method
{
return isBST(r,r.left.key, r.right.key);
}
public boolean isBST(tNode t, int min, int max)
{
if(t == null)
{
return true;
}
if(t.key < min || t.key > max)
{
return false;
}
boolean leftIs = isBST(t.left,min,t.key);
if(!leftIs)
{
return false;
}
return isBST(t.right,t.key+1,max);
}
Please help. I don't know if my min's and max's are right in the calls, and if they are right in the original driver call.
Code tags added. -Narue