摘要: http://blog.csdn.net/whinah/article/details/6419680从理论上讲,只要允许使用栈,所有的递归程序都可以转化成迭代。但是并非所有递归都必须用栈,不用堆栈也可以转化成迭代的,大致有两类尾递归:可以通过简单的变换,让递归作为最后一条语句,并且仅此一个递归调用。// recursiveint fac1(int n) { if (n <= 0) return 1; return n * fac1(n-1);}// iterativeint fac2(int n) { int i = 0, y = 1; for (; i <= n; ... 阅读全文
posted @ 2013-06-13 17:08 Alan Yang 阅读(973) 评论(0) 推荐(1) 编辑
摘要: A child is running up a staircase with N steps, and can hop either 1 step,2steps,3 steps at a time. Count how many possible ways the child can run up the stairs. class Upstaircase { static void Main(string[] args) { /* Enter your code here. Read input from STDIN. Print ou... 阅读全文
posted @ 2013-06-13 00:54 Alan Yang 阅读(361) 评论(0) 推荐(0) 编辑