I'm understanding the question, but I want to know whether or not my implementation is correct.
The question is:
Write a method that accepts as its argument a BinaryTree object and returns true if the argument tree is a binary search tree. Examine each node in the given tree only once.
This is my implementation:
public boolean isBST (BinaryTree<String> tree)
{
BinaryNode Node = new BinaryNode (tree.getRootData);
if(tree == null || Node.isLeaf() )
return true;
if(Node.getData > Node.getLeftChild && Node.getData < Node.getRightChild)
{
boolean leftTree = isBST(new BinaryTree(Node.getLeftChild));
boolean rightTree = isBST(new BinaryTree(Node.getRightChild));
return leftTree && rightTree ;
}
else return false ;
}