摘要: https://zh.wikipedia.org/wiki/%E9%80%92%E5%BD%92递归(英语:Recursion),又译为递回,在数学与计算机科学中,是指在函数的定义中使用函数自身的方法。递归一词还较常用于描述以自相似方法重复事物的过程。例如,当两面镜子相互之间近似平行时,镜中嵌套的图像是以无限递归的形式出现的。语言例子从前有座山,山里有座庙,庙里有个老和尚,正在给小和尚讲故事呢!故事是什么呢?“从前有座山,山里有座庙,庙里有个老和尚,正在给小和尚讲故事呢!故事是什么呢?‘从前有座山,山里有座庙,庙里有个老和尚,正在给小和尚讲故事呢!故事是什么呢?……’”以下是另一个可能更有利于 阅读全文
posted @ 2013-05-27 20:13 IAmAProgrammer 阅读(1170) 评论(0) 推荐(1) 编辑
摘要: http://c2.com/cgi/wiki?TailRecursionRecursive procedures call themselves to work towards a solution to a problem. In simple implementations this balloons the stack as the nesting gets deeper and deeper, reaches the solution, then returns through all of the stack frames. This waste is a common compla 阅读全文
posted @ 2013-05-27 19:06 IAmAProgrammer 阅读(475) 评论(0) 推荐(0) 编辑
摘要: loop [lu:p]、iterate ['itəreit]、traversal [træ'vɜ:sl]和recursion [rɪˈkɜ:ʃn]分别翻译为:循环、迭代、遍历和递归。循环是计算机科学运算领域的用语,也是一种常见的控制流程。循环是一段在程序中只出现一次,但可能会连续运行多次的代码。循环中的代码会运行特定的次数,或者是运行到特定条件成立时退出循环,或者是针对某一集合中的所有项目都运行一次。在计算机科学中,For循环(英语:For loop)是一种编程语言的迭代陈述,能够让程式码反复的执行。它跟其他的循环,如while循环,最大的不同,是它拥有一个循环计数器 阅读全文
posted @ 2013-05-27 17:19 IAmAProgrammer 阅读(2593) 评论(0) 推荐(0) 编辑
摘要: http://stackoverflow.com/questions/6707148/foreach-macro-on-macros-arguments/13459454#13459454recursive macros are possible in C using a fancy workaround. The end goal is to create aMAPmacro which works like this:#define PRINT(a) printf(#a": %d", a)MAP(PRINT, a, b, c) /* Apply PRINT to a, 阅读全文
posted @ 2013-05-27 02:57 IAmAProgrammer 阅读(506) 评论(0) 推荐(0) 编辑
摘要: http://aggregate.org/MAGIC/The Aggregate Magic AlgorithmsThere are lots of people and places that create and collect algorithms of all types (hereare a few WWW sites). Unfortunately, in building systems hardware and software, we inThe Aggregateoften have found it necessary to do relatively obscure l 阅读全文
posted @ 2013-05-27 00:36 IAmAProgrammer 阅读(174) 评论(0) 推荐(0) 编辑
摘要: http://www.hackersdelight.org/hdcodetxt/nlz.c.txt// This has the programs for computing the number of leading zeros// in a word.// Max line length is 57, to fit in hacker.book.// Compile with g++, not gcc.#include <stdio.h>#include <stdlib.h> // To define "exit", req'd by X 阅读全文
posted @ 2013-05-27 00:30 IAmAProgrammer 阅读(311) 评论(0) 推荐(0) 编辑
摘要: http://graphics.stanford.edu/~seander/bithacks.htmlBit Twiddling HacksBy Sean Eron Andersonseander@cs.stanford.eduIndividually, thecode snippets here are in the public domain(unless otherwise noted) — feel free to use them however you please. The aggregate collection and descriptions are ©1997- 阅读全文
posted @ 2013-05-27 00:21 IAmAProgrammer 阅读(204) 评论(0) 推荐(0) 编辑