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

Constructor and Purge Methods

Program gif defines the GeneralTree constructor and Purge methods. According to Definition gif, a general tree must contain at least one node--an empty tree is not allowed. Therefore, the constructor takes one argument, any object instance. The constructor initializes the fields as follows: The key field is assigned the argument; the degree field is set to zero; and, the list field is assigned an empty linked list. The running time of the constructor is clearly O(1).

   program16012
Program: GeneralTree class constructor and Purge methods.

The Purge method of a container normally empties the container. In this case, the container is a general tree which is not allowed to be empty. Thus, the Purge method shown in Program gif discards the subtrees of the tree, but it does not discard the root. The running time of the Purge method is clearly O(1).


next up previous contents index

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