Data Structures and Algorithms with Object-Oriented Design Patterns in Python
next up previous index

accept Method

The accept method of the StackAsLinkedList class is defined in Program gif. The accept method takes a visitor and calls its visit method one-by-one for all of the objects on the stack.

Program: StackAsLinkedList class accept method.

The implementation of the accept method 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 method is called. If tex2html_wrap_inline60701 is the running time of the visit method, the total running time for accept is tex2html_wrap_inline60703, where tex2html_wrap_inline60691 is the number of objects in the container. If we assume that tex2html_wrap_inline60707, the total running time is O(n).

next up previous index

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