tree
Class MyTree

java.lang.Object
  |
  +--tree.MyTree

public class MyTree
extends java.lang.Object

This is a binary search tree. The tree holds integer valued nodes.

See Also:
MyNode

Constructor Summary
MyTree()
          Class constructor.
 
Method Summary
 int cardinal()
          Calculate the number of nodes in this tree.
 MyNode getRoot()
          Return a reference to the root in this tree.
 boolean insert(MyNode node)
          Inserts a node in this tree.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MyTree

public MyTree()
Class constructor.
Method Detail

getRoot

public MyNode getRoot()
Return a reference to the root in this tree.
Returns:
Reference to the root node.

insert

public boolean insert(MyNode node)
Inserts a node in this tree. The tree is sorted by the node values. If a node with the same node value is already in the tree nothing happens. If the inserted node is null nothing happens.
Parameters:
node - The node to insert in this tree.
Returns:
True if node is inserted, false otherwise.

cardinal

public int cardinal()
Calculate the number of nodes in this tree. Recursively calculate the number of nodes in this binary search tree.
Returns:
The total number of nodes.