Tree Insertion

4 Binary Search Tree Designs (ppt)

Simple Tree

2 class contruction.
The simplest and most common design but perhaps the hardest to debug as errors almost always require fixing twice. Once on the left, and once on the right.

Sample Tree

3 class contruction.
Eliminates the repetition by adding a level of indirection.

Another Tree

2 class contruction.
Eliminates the repetition using return values instead of a third class. Probably harder to implement as the return values require some thought.

Yet Another Tree

1 class contruction.
Eliminates the repetition by changing the empty tree from null to a tree node with null data. This is perhaps the only pure object oriented design of the bunch.

More designs are possible

A parent pointer can change the design and/or the abstraction