Unformatted text preview: hat node in its
else // find ancestor
while (curr->parent != 0 &&
(curr(curr->parent)(curr->parent)->left != curr)
curr = curr->parent;
currcurr = curr->parent;
curr} We either find it, or we are at the rightmost node
of the whole tree (finished). 13 What was all this for?
We can now find the next node in inorder
traversal from any node in the tree.
Suppose we use a iterator to travel through the
void SetIterator(nodePtr root);//find leftmost node
void* Next(nodePtr root);
//return next item
bool More(nodePtr root); //any more nodes? Here's the function to see if there is any more of
the tree to iterate through.
bool More(nodePtr root)
return (curr != 0);
} And finally there is Next, the iterator itself.
Next OK. So just how efficient are these trees?
A tree contains at most 1, 2, 4, 8, ... , 2n nodes at
Or, we need level for node, levels for
Or, we need 1 level for 1 node, 2 levels for 3
nodes, 3 levels for 7 nodes, . . ., n levels...
View Full Document