Data Structures and Algorithms
with Object-Oriented Design Patterns in C#|
Program defines the Accept method for the StackAsArray class. As discussed in Chapter , the purpose of the Accept method of a container is to accept a visitor and to cause it to visit one-by-one all of the contained objects.
Program: StackAsArray class Accept method.
The body of the Accept method is simply a loop which calls the Visit method for each object in the stack. The running time of the Accept method depends on the running time of the Visit method. Let be the running time of the Visit method. In addition to the time for the method call, each iteration of the loop incurs a constant overhead. Consequently, the total running time for Accept is , where n is the number of objects in the container. And if , the total running time is to O(n).