recursion using only heap area

前端 未结 6 1640
你的背包
你的背包 2021-02-10 08:51

Are there examples of recursion using only heap area?

6条回答
  •  孤城傲影
    2021-02-10 09:19

    In C, function call-based recursion always uses the stack, almost by definition.

    If you are willing to convert your recursion to iteration, then it is possible to use only heap space, but that isn't really recursion. You would do so by implementing a stack in the heap.

    Certain problems can use tail recursion, which repeatedly overwrites the same area of the stack.

提交回复
热议问题