i'm understanding the question but wanna make sure if my implementation is correct or not =|
The Q 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 java code :
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 ;
}