in reply to Re^2: An iterator for (not "iterating") a recursive data structure. (terser)
in thread An iterator for (not "iterating") a recursive data structure.
It's identical to what you'd use for a breadth-first search (as an iterator or otherwise) except then you'd use a queue instead of a stack for a breadth-first search. In both cases, you need to save the search state in a local var rather than using recursion to save it on the system stack.