Iterator (4.2)

This exercise is in two parts.

The first part is about implementing simple classes for binary search trees. A binary tree is either a Leaf or a Branch consisting of an Element (referred to as the decoration) and two binary trees (referred to as the left and right child, respectively). A binary search tree is a binary tree with some additional properties: there is a total ordering on the decorations; the children of a Branch are binary search trees; and the decoration of a Branch follows all the decorations of the left child and precedes all the decorations of the right child.

The second part of the exercise is about an iterator for a binary search tree. The iterator implements the java.util.Enumeration interface, which is intended exactly for iterators. The iterator of many collections is generally obtained by invoking a method, conventionally called elements(), of the collection, e.g., see java.util.Vector and java.util.Hashtable. There are many ways to iterate the elements of a binary tree. For ease of testing, code an in-order iterator. Recall that that the in-order traversal of a Branch visits the left-child before the decoration and the right child after the decoration.

Design, code and test a binary (search) tree class and an in-order iterator for this class.