递归函数的例子 [英] Examples of Recursive functions

查看:47
本文介绍了递归函数的例子的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以建议说明递归函数的编程示例吗?有常见的老马,例如Fibonacci series河内塔,但除了它们之外的任何东西都会很有趣.

解决方案

本图是英文,而不是实际的编程语言,但对于以非技术方式解释过程很有用:

<前>一个孩子睡不着,所以她妈妈讲了一个关于一只小青蛙的故事,谁睡不着,所以青蛙的妈妈讲了一个小熊的故事,谁睡不着,所以熊妈妈讲了一个小黄鼠狼的故事……谁睡着了.……小熊睡着了;……小青蛙睡着了;……孩子睡着了.

Can anybody suggest programming examples that illustrate recursive functions? There are the usual old horses such as Fibonacci series and Towers of Hanoi, but anything besides them would be fun.

解决方案

This illustration is in English, rather than an actual programming language, but is useful for explaining the process in a non-technical way:

A child couldn't sleep, so her mother told a story about a little frog,
  who couldn't sleep, so the frog's mother told a story about a little bear,
     who couldn't sleep, so bear's mother told a story about a little weasel
       ...who fell asleep.
     ...and the little bear fell asleep;
  ...and the little frog fell asleep;
...and the child fell asleep.

这篇关于递归函数的例子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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