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

Constructor and Purge Methods

The definitions of the StackAsArray constructor and Purge methods are given in Program gif. The constructor takes a single parameter, size, which specifies the maximum number of items that can be stored in the stack. The variable array is initialized to be an array of length size. The constructor requires O(n) time to construct the array, where tex2html_wrap_inline60461.

   program5354
Program: StackAsArray class constructor and Purge methods.

The purpose of the Purge method is to remove all the contents of a container. In this case, the objects in the stack occupy the first count positions of the array. To empty the stack, the Purge method simply assigns the value null to the first count positions of the array. Clearly, the running time for the Purge method is O(n), where tex2html_wrap_inline60465.


next up previous contents index

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