今天复习了一下二叉树的前序遍历、中序遍历、后序遍历的递归与非递归算法,顺便记录一下://TreeTest.h#include struct TreeNode{ int value; TreeNode* leftChild; TreeNode* rightChild; void...
分类:
编程语言 时间:
2015-03-06 00:58:18
阅读次数:
210
class Node{public: int data; Node* left; Node* right;};void pre-order(Node* root){ stack stk; if (root) stk.push(root); while...
分类:
其他好文 时间:
2015-02-24 16:16:46
阅读次数:
122
重建二叉树
时间限制:1000 ms | 内存限制:65535 KB
难度:3
描述题目很简单,给你一棵二叉树的后序和中序序列,求出它的前序序列(So easy!)。
输入输入有多组数据(少于100组),以文件结尾结束。
每组数据仅一行,包括两个字符串,中间用空格隔开,分别表示二叉树的后序和中序序列(字符串长度小于26,输入数据保证合法)。
输出每组输出...
分类:
其他好文 时间:
2015-02-22 14:38:22
阅读次数:
131
节点深度:从根到节点的路径长度,d(root)=0节点高度:从节点到树叶的最长路径的长,h(leaf)=0树高为根高,树的深度=树的高度树的遍历:递归的前、中、后序还是蛮简单的: 1 //树的遍历 2 void preorder_recursive(PtrToBiNode T){ //二叉树递归.....
分类:
其他好文 时间:
2015-02-20 17:24:46
阅读次数:
235
Given inorder and postorder traversal of a tree, construct the binary tree.Note:You may assume that duplicates do not exist in the tree.这道题要求从中序和后序遍历的...
分类:
其他好文 时间:
2015-02-19 18:37:40
阅读次数:
221
由先序遍历和中序遍历序列可唯一还原出二叉树,前提条件是所有节点的关键字无重复。题目来源:http://hihocoder.com/problemset/problem/1049代码: 1 #include 2 #include 3 4 using namespace std; 5 6 voi...
分类:
其他好文 时间:
2015-02-18 11:50:18
阅读次数:
162
Given inorder and postorder traversal of a tree, construct the binary tree.Note:You may assume that duplicates do not exist in the tree.[Solution]后序定根...
分类:
其他好文 时间:
2015-02-18 11:50:07
阅读次数:
129
求二叉树的先序遍历Time Limit: 1000ms Memory limit: 65536K有疑问?点这里^_^题目描写叙述已知一棵二叉树的中序遍历和后序遍历,求二叉树的先序遍历输入输入数据有多组,第一行是一个整数t (t#include #include struct node{ cha...
分类:
其他好文 时间:
2015-02-17 22:13:40
阅读次数:
207
根据序遍历的特点,我们可以知道,对任意一棵二叉树tree,其后序遍历(ch)的最后一个字符就是这课二叉树的根节点x,然后我们可以在其中序遍历(sh)中把x找出来(假设为第i个字符),显然中序遍历中x前面的字符串(copy(sh,1,i-1))是tree的左子树的中序遍历,x后面的字符串是tree的....
分类:
其他好文 时间:
2015-02-15 14:49:13
阅读次数:
164