The Accept member function of the StackAsLinkedList class is defined in Program . The Accept member function takes a visitor and calls its Visit function one-by-one for all of the objects on the stack.
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 . 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 is the running time of the function Visit, the total running time for Accept is , where is the number of objects in the container. If we assume that , the total running time is O(n).