in reply to Re^3: Eliminating Recursive Tree Walking by using MJD-style Infinite Streams?
in thread Eliminating Recursive Tree Walking by using MJD-style Infinite Streams?
In case you're curious,
only requires as many nodes on the stack as the max depth of the tree.
So does mine below.
It does this by creating an iterator (one item) for the stack instead of a list of nodes (many) to visit.
Mine doesn't wrap the array index in an iterator. I started making a version that did, but it was complicating the ability to return the path that led to the node (like the OP's) instead of just the node (like yours).
|
---|