Data Structures and Algorithms
with Object-Oriented Design Patterns in C# |
Program defines the GeneralTree constructor and Purge methods. According to Definition , 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).
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 discards the subtrees of the tree, but it does not discard the root. The running time of the Purge method is clearly O(1).