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

The Accept Member Function

The Accept member function of the StackAsLinkedList class is defined in Program gif. The Accept member function takes a visitor and calls its Visit function one-by-one for all of the objects on the stack.

   program6106
Program: StackAsLinkedList Class Accept Member Function Definition

The implementation of the Accept function for the StackAsLinkedList class mirrors that of the StackAsArray class shown in Program gif. In this case, the linked list is traversed from front to back, i.e., from the top of the stack to the bottom. As each element of the linked list is encountered, the Visit function is called. If tex2html_wrap_inline61326 is the running time of the function Visit, the total running time for Accept is tex2html_wrap_inline61328, where tex2html_wrap_inline61308 is the number of objects in the container. If we assume that tex2html_wrap_inline61332, the total running time is O(n).


next up previous contents index

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