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

accept Method

The AbstractTree class replaces the functionality provided by the single method accept with two different kinds of traversal. Whereas the accept method is allowed to visit the nodes of a tree in any order, the tree traversals visit the nodes in two different, but well-defined orders. Consequently, we have chosen to provide a default implementation of the accept method which does a preorder traversal.

Program gif shows the implementation of the accept method of the AbstractTree class. This method uses the PreOrder adapter to pass on a given visitor to the depthFirstTraversal method.

   program15609
Program: AbstractTree class accept method.


next up previous contents index

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