Tree Walking

Additional example

Comments are moderated. It may take a few minutes before your comment appears.
Markdown is supported in your comments.

Typically child links are treated as points where the code should recurse, and this recursion should happen in the language's stack. An alternative is to build your own stack and iterate over that. Each node contains references to child objects that need to be examined. Think of it as a "todo list" of nodes to look at next. Instead of recursing through the nodes, add the nodes you want to look at next (i.e., the child links) onto a "master todo list". Then iterate over the list.

Mail: (not shown)

Please type this: