Java Reference
In-Depth Information
To insert data into the tree, use the following algorithm:
ȗ If you encounter a non- null node reference, look at its data value. If the
data value of that node is larger than the one you want to insert, continue the
process with the left child. If the existing data value is smaller, continue the
process with the right child.
ȗ If you encounter a null node reference, replace it with the new node.
Figure 9
Binary Search Tree After Four Insertions
722
723
For example, consider the tree in Figure 9 . It is the result of the following statements:
BinarySearchTree tree = new BinarySearchTree();
tree.add(ÐJulietÑ);
Search WWH ::




Custom Search