1 二叉树的递归遍历 二叉树在数据结构中乃是重中之重,其应用非常广泛,很多数据结构都是建立在二叉树的基础上,如红黑色,平衡树等。 二叉树的定义如下: 一个有穷的结点集合。 这个集合可以为空。 若不为空,则它是由根结点和称为其左子树TL和右子树TR的两个不相交的二叉树组成。 可...
分类:
其他好文 时间:
2015-10-07 12:11:19
阅读次数:
286
public static XmlDocument FileMergedIntoXML(string strXmlPathPublic) { string strXmlPathPublic = string.Format(@"{0}file1.xml", AppDomain.Curr...
分类:
其他好文 时间:
2015-09-23 10:10:25
阅读次数:
98
import java.io.*;import java.util.*;public class Main{ public static void main(String args[]) { Scanner cin = new Scanner(System.in); ...
分类:
编程语言 时间:
2015-09-15 12:52:31
阅读次数:
243
二叉树的前中后序遍历,可以用递归秒解,看起来不值一提。但如果不允许采用递归,要怎么实现呢?还是先来看看递归算法的实现吧:def visit( root): if root is not null: #1 visit(root.left) ...
分类:
其他好文 时间:
2015-09-07 21:12:22
阅读次数:
174
1.最容易想到的方法:递归遍历每个点,计算出总的点数,时间复杂度O(n),很不幸,超时了。(不超也说不过去啊==)
class Solution {
public:
int countNodes(TreeNode* root) {
if(root==NULL)
return 0;
int res=0;
if(root->le...
分类:
其他好文 时间:
2015-08-31 21:41:58
阅读次数:
129
栈模拟非递归算法递归算法的本质是利用函数的调用栈进行,实际上我们可以自行使用栈来进行模拟,这样的算法空间复杂度为O(h),h为二叉树的高度。前序遍历首先把根节点入栈,然后在每次循环中执行以下操作:此时栈顶元素即为当前的根节点,弹出并打印当前的根节点。把当前根节点的右儿子和左儿子分别入栈(注意是右儿子...
分类:
编程语言 时间:
2015-08-30 11:07:19
阅读次数:
220
递归算法
void preorder1(Node *root) //递归前序遍历
{
if (root == NULL) return;
printf("%d ", root->val);
preorder1(root->left);
preorder1(root->right);
}
void inorder1(Node *root) //递归中序遍历
{
if (root == ...
分类:
其他好文 时间:
2015-08-29 17:04:03
阅读次数:
151
import java.io.File;/** * 递归遍历 * */public class FieTree { public static void main(String[] args) { File f = new File("D:/java笔记"); pr...
分类:
编程语言 时间:
2015-08-17 06:28:31
阅读次数:
157
#include #include #include #include using namespace std;typedef struct node{ int flag; char value; struct node *lchild; struct node *rchil...
分类:
其他好文 时间:
2015-08-17 00:37:16
阅读次数:
131
#include
#include
#include
#include
#include
using namespace std;struct Node
{
char data;
Node *left;
Node *right;
Node(char d = char()):data...
分类:
其他好文 时间:
2015-08-16 23:11:46
阅读次数:
173