in reply to Unrolling recursion
One general technique is to use a stack:
And depth/breadth first recursion can be adjusted by shifting instead of popping at the top of the loop (or when inserting new work).seed the stack with the first instance while (stack has entries) pop off top entry from stack process it take any potential new work as a result of processing, put it back on the stack
Of course this only replaces the subroutine stack with your own, but it can be quicker and save memory. (Sometimes it's a lot more obvious too!)
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Re: Unrolling recursion
by clintp (Curate) on Mar 14, 2002 at 15:15 UTC | |
by broquaint (Abbot) on Mar 14, 2002 at 15:47 UTC |
In Section
Meditations