Can every recursion be converted into iteration?

前端 未结 17 2287
遥遥无期
遥遥无期 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:15

    I'd say yes - a function call is nothing but a goto and a stack operation (roughly speaking). All you need to do is imitate the stack that's built while invoking functions and do something similar as a goto (you may imitate gotos with languages that don't explicitly have this keyword too).

提交回复
热议问题