Data Structures and Algorithms
with Object-Oriented Design Patterns in C#![]() ![]() ![]() ![]() ![]() |
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 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.
Program: AbstractTree class Accept method.