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

AttachSubtree and DetachSubtree Member Functions

Program gif also defines two functions for manipulating the subtrees of a general tree. The purpose of the AttachSubtree member function is to add the specified subtree to the root of a given tree. This function takes as its lone argument a reference to a GeneralTree instance which is to be attached. The AttachSubtree routine simply appends to the linked list a pointer to the tree to be attached and then adds one the degree variable. The running time for AttachSubtree is O(1).

Similarly, the DetachSubtree member function removes the specified subtree from the given tree. This function takes as its lone argument a reference to a GeneralTree instance which is to be removed. It removes the appropriate pointer from the linked list and then subtracts one from the degree variable. The running time for DetachSubtree is O(d) in the worst case, where tex2html_wrap_inline63952.


next up previous contents index

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