[Solved] How do I trace the progress of this tree code?


Without tracing, it’s relatively straightforward to see what a given tree should print. The structure of the method means that a string will look like this:

<content><left sub-tree><content><right sub-tree><content>

So all you have to do is continually substitute that pattern for the left and right sub-trees (with empty strings for non-existent sub-trees) and get the string.

For your example tree, it looks like this (using [ and ] to show substitutions):

A<left sub-tree>A<right sub-tree>A
A[B<left sub-tree>B<right sub-tree>B]A[C<left sub-tree>C<right sub-tree>C]A
A[B[]B[D<left sub-tree>D<right sub-tree>D]B]A[C[E<left sub-tree>E<right sub-tree>E]C[]C]A
A[B[]B[D[]D[]D]B]A[C[E[]E[]E]C[]C]A

So the method prints out ABBDDDBACEEECCA

solved How do I trace the progress of this tree code?