This preview shows page 1. Sign up to view the full content.
Unformatted text preview: temp = temp->right_sibling(); } return count; } 6.5 The Weighted Union Rule requires that when two parent-pointer trees are merged, the smaller ones root becomes a child of the larger ones root. Thus, we need to keep track of the number of nodes in a tree. To do so, modify the node array to store an integer value with each node. Initially, each node is in its own tree, so the weights for each node begin as 1. Whenever we wish to merge two trees, check the weights of the roots to determine which has more nodes. Then, add to the weight of the f nal root the weight of the new subtree. 6.6 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15-1 6 9 12 6.7 The resulting tree should have the following structure:...
View Full Document
- Fall '08