哪些递归函数不能用循环重写? [英] Which recursive functions cannot be rewritten using loops?

查看:46
本文介绍了哪些递归函数不能用循环重写?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

据我所知,大多数递归函数都可以使用循环重写.有些可能比其他的更难,但大多数都可以重写.

As far as I know, most recursive functions can be rewritten using loops. Some may be harder than others, but most of them can be rewritten.

在什么情况下不可能使用循环重写递归函数(如果存在这种情况)?

Under which conditions does it become impossible to rewrite a recursive function using a loop (if such conditions exist)?

推荐答案

当您以递归方式使用函数时,编译器会为您处理堆栈管理,这使得递归成为可能.任何可以递归执行的操作,都可以通过自己管理堆栈来完成(对于间接递归,您只需确保不同的函数共享该堆栈).

When you use a function recursively, the compiler takes care of stack management for you, which is what makes recursion possible. Anything you can do recursively, you can do by managing a stack yourself (for indirect recursion, you just have to make sure your different functions share that stack).

所以,不,没有什么可以用递归来完成,也不能用循环和堆栈来完成.

So, no, there is nothing that can be done with recursion and that cannot be done with a loop and a stack.

这篇关于哪些递归函数不能用循环重写?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆