递归
oceanZwl
态度决定一切
展开
-
彻底理解递归
一:简单实例 1.阶乘的实现 写个函数实现 N! = N × (N-1) × (N-2) × ... × 2 × 1 [java] view plaincopyprint? public static int factorial(int N) { if (N == 1) return 1; return N * factorial(N-1转载 2014-03-24 11:22:25 · 586 阅读 · 0 评论 -
树的三种遍历(递归与非递归实现)
1:深度优先 1.1:前序遍历 Visit the root.Traverse the left subtree.Traverse the right subtree. 如下图: Pre-order: F, B, A, D, C, E, G, I, H 伪代码: preorder(node) if node == null t转载 2014-03-24 11:26:57 · 637 阅读 · 0 评论