Data Structures and Algorithms with Object-Oriented Design Patterns in C#
next up previous contents 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.

   program5596
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_inline60475 is the running time of the Visit method, the total running time for Accept is tex2html_wrap_inline60477, where tex2html_wrap_inline60465 is the number of objects in the container. If we assume that tex2html_wrap_inline60481, the total running time is O(n).


next up previous contents index

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