jw wrote:
root=+
root->right=x x->left=3 x->right=2
root->left=x x->left=2 x->right=- - ->left=5
- ->right1
So, as I get it, it's like this
.. [ + ]
.. / \
.. [ x ] [ x ]
.. / \ / \
.. [ 2 ] [ - ] [ 3 ] [ 2 ]
.. / \
.. [ 5 ] [ 1 ]
What should it print? First it takes the root, right? Then it sees that
the left (the 'x') is not NULL. So, it prints the parenthesis first, and
then the left tree. How? What does it mean to print a tree when the left
'x' is now a temporary root? It looks at its left. It's not NULL (it's
the leftmost '2'), so it prints another parenthesis, and then the subtree
where the leftmost '2' is the new root. How? Its left is NULL, its
'element' is "2", and its right is NULL. Then it returns. Where? To
print the rest of the left 'x' subtree. How? It prints the element, it's
"x", then it see that the right is not NULL. It prints the right subtree
(with the '-' as its root). How? ...
Continue until you finish printing the right part of the '+'.
I don't see any C++ question, by the way. Next time post to a newsgroup
where your general programming question is more topical, comp.programming.
V