Data Structures and Algorithms
with Object-Oriented Design Patterns in C#![]() ![]() ![]() ![]() ![]() |
Program 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).
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 ,
where degree is the degree of the root node of the tree.
It returns the
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
is the degree of the root node of the tree.