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

attachSubtree and detachSubtree Methods

Program gif also defines two methods for manipulating the subtrees of a general tree. The purpose of the attachSubtree method is to add the specified subtree to the root of a given tree. This method takes as its argument a GeneralTree instance which is to be attached. The attachSubtree method 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 method removes the specified subtree from the given tree. This method takes as its argument the GeneralTree instance which is to be removed. It removes the appropriate item 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_inline62818.


next up previous contents index

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