Logo Data Structures and Algorithms with Object-Oriented Design Patterns in C++
next up previous contents index

Accept Member Function

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

Program gif shows the implementation of the Accept member function of the Tree class. This function uses the PreOrder adapter to pass on a given visitor to the DepthFirstTraversal routine.

   program16317
Program: Tree Class Accept Member Function Definition


next up previous contents index

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