Java Reference
In-Depth Information
Name (blank to quit)? Howard
Name (blank to quit)? Penny
Name (blank to quit)? Raj
Name (blank to quit)? Leslie
Name (blank to quit)? Ma
Name (blank to quit)?
Alphabetized list:
Howard
Leonard
Leslie
Ma
Penny
Raj
Sheldon
Next int (0 to quit)? 38
Next int (0 to quit)? 19
Next int (0 to quit)? -47
Next int (0 to quit)? 2
Next int (0 to quit)? 42
Next int (0 to quit)? 13
Next int (0 to quit)? 9
Next int (0 to quit)? 0
Sorted list:
-47
2
9
13
19
38
42
To generate the SearchTree class, we can start with the IntSearchTree class
and convert it into generic form.
First we need a node class for the tree. Our node class is almost the same as the
IntTreeNode class, but instead of having data of type int , we have data of type E ,
and instead of saying IntTreeNode , we have to say SearchTreeNode<E> in most
places other than the constructor headers:
1 public class SearchTreeNode<E> {
2 public E data; // data stored in this node
3 public SearchTreeNode<E> left; // left subtree
4 public SearchTreeNode<E> right; // right subtree
 
Search WWH ::




Custom Search