Tree Walking

Additional example

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

A deque provides the best of both. It is a nifty structure (based on a double linked list) that is both stack and FIFO. For each node of the tree, add the children to either the front (FIFO like) or the back (stack like) of the deque. Meanwhile iterate over the deque by popping off the back.

Mail: (not shown)

Please type this: