Can every recursion be converted into iteration?

前端 未结 17 2320
遥遥无期
遥遥无期 2020-11-22 01:59

A reddit thread brought up an apparently interesting question:

Tail recursive functions can trivially be converted into iterative functions. Other one

17条回答
  •  故里飘歌
    2020-11-22 02:24

    Yes, it's always possible to write a non-recursive version. The trivial solution is to use a stack data structure and simulate the recursive execution.

提交回复
热议问题