Sample Response:
Pathetic "Error", Eddy!!
What we want is bloomin subtle pitfalls, not sheer bumbling ...
Right so let's get the "Visit" part right for starters and try to mess up the "Traverse" bit only? Keep things simple.
My truncated reading of the def. for "Visit" is "ACT". One could also call it something like "DO". Or if one is verbose: "do_stuff_with_or_to_this_Object".
So step 1 is a proper visit. "ToDo" here is "print the name of the Node".
A
very nice. So on to step 2
Traverse the left subtree. OK so that would actually be like a complete traversal of some terrain, right? Like climbing all the branches of some tree? So we'd have
B,C,D. That's the left traversed.
OK but we still haven't traversed the right inside the traverse. So F then. In preorder.
So write down F
F .. we have AF so far.
Step2. Nothing there on the left. Step 3 Nothing there on the right.
... So now I suppose we go back up to the calling node ... which was? A, right?
and then finish off what was happening there. "Visit"? Done. "LeftTrav?" Done. So we do a Traverse of the Right hand subtree.
So the Whole Subtree.
Rightwards.
GLM and we're at the top or bottom. OK so preorder means the Visit-is-Pre. Write the value
M .... Giving us AFM so far.
Then "Left" ... nothing.
"Right" ... nothing.
... and then Back.
Which takes us back to A, and whee hah! We're done.
No it's not a very good error....
Did I ever claim that this was Easy??