12419 shaares
291 private links
291 private links
instead of letting the call stack implicitly control what happens next (as recursion does), store the pending work in an explicit data structure such as a stack, queue, or heap. This turns control flow into ordinary data that can be inspected, paused, modified, or resumed.
Explicit stacks makes interruptions, limits, cancellation or interleaving work easier to work with. It's more adaptable to real-world constraints and test.
A stack (LIFO) produces depth-first search behavior.
A queue (FIFO) produces breadth-first search behavior.