设计模式转换递归算法迭代的人 [英] Design patterns for converting recursive algorithms to iterative ones

查看:180
本文介绍了设计模式转换递归算法迭代的人的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有任何一般的启发,提示,技巧,或常见的设计范例,可以用来递归算法转换为一个迭代?我知道这是可以做到的,我不知道是否有做法值得做的事情,所以当牢记。

Are there any general heuristics, tips, tricks, or common design paradigms that can be employed to convert a recursive algorithm to an iterative one? I know it can be done, I'm wondering if there are practices worth keeping in mind when doing so.

推荐答案

您可以经常完全preserve递归算法的原始结构,但要避免堆栈,采用尾调用和更改为 continuation-通过,所建议的此博客条目。 (我真的应该煮了更好的独立的例子。)

You can often entirely preserve the original structure of a recursive algorithm, but avoid the stack, by employing tail calls and changing to continuation-passing, as suggested by this blog entry. (I should really cook up a better standalone example.)

这篇关于设计模式转换递归算法迭代的人的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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