1 #include 2 #include 3 #include 4 #include 5 #include 6 7 typedef void (__stdcall *P_WALK_DIR_CALLBACK)(const std::string &In_strFilePath); 8 ...
分类:
编程语言 时间:
2014-07-16 19:31:47
阅读次数:
256
先写下这个问题的模式
def preorderTraversal(self, root):
if root == None: return []
re = []
insert root to stack s
while s not empty:
cur_root = top of stack s
s.pop()
how to handle cur_root
how to ...
分类:
其他好文 时间:
2014-07-15 10:17:43
阅读次数:
274
n个骰子的点数(非递归) 代码(C)本文地址: http://blog.csdn.net/caroline_wendy题目: 把n个骰子仍在地上, 所有骰子朝上一面的点数之和为s. 输入n, 打印出s的所有可能的值出现的概率.每次骰子的循环过程中, 本次等于上一次n-1, n-2, n-3, n-4, n-5, n-6的次数的总和.代码:/*
* main.cpp
*
* Created ...
分类:
其他好文 时间:
2014-07-12 22:49:18
阅读次数:
269
首先说明一下快速排序是对冒泡排序的改进。为什么这么说呢?想一下冒泡排序,它把序列分成了两部分,前半部分无序,后半部分升序排列,并且后半部分的数都大于前半部的数。由此可得到快速排序和冒泡排序的一些共同点:都要经历n趟排序每趟排序要经历O(n)次比较都是后半部分元素比前半部大而不同之处就在于冒泡排序的交...
分类:
其他好文 时间:
2014-07-11 10:47:33
阅读次数:
251
1.先序遍历非递归算法
#define maxsize 100
typedef struct {
Bitree Elem[maxsize];
int top;
} SqStack;
void PreOrderUnrec(Bitree t) {
SqStack s;
StackInit(s);
p=t;
while (p!=...
分类:
其他好文 时间:
2014-07-08 17:13:18
阅读次数:
267
前言
在前两篇文章二叉树和二叉搜索树中已经涉及到了二叉树的三种遍历。递归写法,只要理解思想,几行代码。可是非递归写法却很不容易。这里特地总结下,透彻解析它们的非递归写法。其中,中序遍历的非递归写法最简单,后序遍历最难。我们的讨论基础是这样的:...
分类:
其他好文 时间:
2014-07-08 16:16:25
阅读次数:
369
1 /** 2 * Definition for binary tree 3 * public class TreeNode { 4 * int val; 5 * TreeNode left; 6 * TreeNode right; 7 * TreeNo...
分类:
其他好文 时间:
2014-07-05 16:53:34
阅读次数:
177
1,什么是栈溢出?由于栈一般默觉得1-2m,一旦出现死循环或者是大量的递归调用,在不断的压栈过程中,造成栈容量超过1m而导致溢出。2,解决方式:方法一:用栈把递归转换成非递归通常,一个函数在调用还有一个函数之前,要作例如以下的事情:a)将实在參数,返回地址等信息传递给被调用函数保存; b)为被调用函...
分类:
其他好文 时间:
2014-07-02 19:02:57
阅读次数:
175
【题目】
Given a binary tree, return the postorder traversal of its nodes' values.
For example:
Given binary tree {1,#,2,3},
1
2
/
3
return [3,2,1].
Note: Recursive solution is trivial, could you do it iteratively?
【题意】
非递归实现后续遍...
分类:
其他好文 时间:
2014-06-30 10:10:10
阅读次数:
177
【题目】
Given a binary tree, return the preorder traversal of its nodes' values.
For example:
Given binary tree {1,#,2,3},
1
2
/
3
return [1,2,3].
Note: Recursive solution is trivial, could you do it iteratively?
【题意】
非递归返回先序遍历...
分类:
其他好文 时间:
2014-06-30 06:21:18
阅读次数:
334