How to convert a recursive function to use a stack?

前端 未结 4 1990
独厮守ぢ
独厮守ぢ 2020-12-05 06:00

Suppose that I have a tree to traverse using a Depth First Search, and that my algorithm for traversing it looks something like this:

algorithm search(NODE):         


        
4条回答
  •  攒了一身酷
    2020-12-05 06:12

    Eric Lippert has created a number of posts about this subject. For example take a look at this one: Recursion, Part Two: Unrolling a Recursive Function With an Explicit Stack

提交回复
热议问题