Cover Data Structures and Algorithms with Object-Oriented Design Patterns in Java
next up previous contents index

accept Method

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

   program5379
Program: StackAsArray class accept method.

The body of the accept method is simply a loop which calls the visit method for each object in the stack. The running time of the accept method depends on the running time of the visit method. Let tex2html_wrap_inline60206 be the running time of the visit method. In addition to the time for the method call, each iteration of the loop incurs a constant overhead. Consequently, the total running time for accept is tex2html_wrap_inline60208, where n is the number of objects in the container. And if tex2html_wrap_inline60212, the total running time is to O(n).


next up previous contents index

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