Data Structures and Algorithms with Object-Oriented Design Patterns in C#
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.

   program15702
Program: AbstractTree class Accept method.


next up previous contents index

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