Cover Data Structures and Algorithms with Object-Oriented Design Patterns in Java
next up previous contents index

Implementing Search Trees

Since search trees are designed to support efficient searching, it is only appropriate that they implement the SearchableContainer interface. Recall from Section gif that the searchable container interface includes the methods find, isMember, insert, and withdraw.

   figure18450
Figure: Object class hierarchy

Program gif defines the SearchTree interface. The SearchTree interface extends the Tree interface defined in Program gif and the SearchableContainer interface defined in Program gif.

   program18464
Program: SearchTree interface.

In addition, two more methods are defined--findMin and findMax. The findMin method returns the object contained in the search tree having the smallest key. Similarly, the findMax method returns the contained object having the largest key.




next up previous contents index

Bruno Copyright © 1998 by Bruno R. Preiss, P.Eng. All rights reserved.