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

The Accept Member Function

Program gif defines the Accept member function for the StackAsArray class. As discussed in Chapter gif, the purpose of the Accept member function of a container, is to accept a visitor, and cause it to visit one-by-one all of the contained objects.

   program5914
Program: StackAsArray Class Accept Member Function Definition

In the array implementation of the stack, the elements contained in the container occupy positions 0, 1, ..., tex2html_wrap_inline61316 of the array. The body of the Accept function is simply a loop which calls the Visit function for each object in the stack. The running time of the Accept function depends on the running time of the function Visit. Let tex2html_wrap_inline61326 be the running time of the function Visit. In addition to the time for the function call, each iteration of the loop incurs a constant overhead. Consequently, the total running time for Accept is tex2html_wrap_inline61328, where n is the number of objects in the container. And if tex2html_wrap_inline61332, the total running time is to O(n).


next up previous contents index

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