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

Constructor

The code for the TreeEnumeration constructor method is given in Program gif. The constructor is quite simple. First, a new instance of the StackAsLinkedList class is created. (The linked-list implementation of stacks is described in Section gif). Then, the tree is pushed onto the stack (provided it is not the empty tree).

   program15659
Program: AbstractTree TreeEnumeration constructor.

An empty stack can be created in in constant time. In addition, the tree can be pushed onto the empty stack in constant time. Therefore, the running time of the constructor is O(1).


next up previous contents index

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