To complement my earlier questions:
- How to perform a breadth-first traversal of an expression?
- How to perform a depth-first preorder traversal of an expression?
I would now like to ask: how to perform a depth-first in-order traversal?
Wikipedia gives this illustration of the depth-first in-order traversal:
The output is A, B, C, D, E, F, G, H, I.
I believe this traversal applies only to binary trees.
Here is an expression to experiment with, using Null
for missing leaves.
tree = "F"["B"["A", "D"["C", "E"]], "G"[Null, "I"["H", Null]]];
I am interested in efficiency and elegance.