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

Key Property and GetSubtree Method

Program gif defines the various GeneralTree class methods for manipulating general trees. The Key property provides a get accessor that returns the object contained by the root node of the tree. Clearly, its running time is O(1).

   program16033
Program: GeneralTree class Key property, GetSubtree, AttachSubtreeand DetachSubtree methods.

The GetSubtree method takes as its argument an int, i, which must be between 0 and tex2html_wrap_inline63079, where degree is the degree of the root node of the tree. It returns the tex2html_wrap_inline63081 subtree of the given tree. The GetSubtree method simply takes i steps down the linked list and returns the appropriate subtree. Assuming that i is valid, the worst case running time for GetSubtree is O(d), where tex2html_wrap_inline63085 is the degree of the root node of the tree.


next up previous contents index

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