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-08-04 22:53:02
阅读次数:
195
这是一个二叉树
8
/ 6 7
/ /
4 5
\ / 1 2 3
Preorder : {8} 6 4 1 7 5 2 3
Inorder : 4 1 6 {8} 2 5 3 7...
分类:
其他好文 时间:
2015-08-02 18:17:08
阅读次数:
119
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-08-01 22:10:16
阅读次数:
150
Given preorder and inorder traversal of a tree, construct the binary tree.
Note:
You may assume that duplicates do not exist in the tree.
思路:首先根据前序遍历得到根节点,然后在中序遍历中得到根节点的位置,左边的为左子树,右边的为右子树。
然后再...
分类:
其他好文 时间:
2015-08-01 22:09:32
阅读次数:
138
int PreOrder[1000], InOrder[1000];int flag, n;typedef struct BiTNode { int data; struct BiTNode *LChild, RChild;} BiTNode, *BiTree;void PostOrde...
分类:
其他好文 时间:
2015-08-01 20:25:26
阅读次数:
111
int InOrder[1000], PosterOrder[1000];typedef struct BiTNode { int data; struct BiTNode *LChild, *RChild;} BiTNode, *BiTree;int find(int *InOrder...
分类:
其他好文 时间:
2015-08-01 20:20:28
阅读次数:
107
/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x...
分类:
其他好文 时间:
2015-07-30 09:29:33
阅读次数:
195
Given inorder and postorder traversal of a tree, construct the binary tree.Note:You may assume that duplicates do not exist in the tree.Analyse: The l...
分类:
其他好文 时间:
2015-07-29 22:37:52
阅读次数:
112
Given preorder and inorder traversal of a tree, construct the binary tree.Note:You may assume that duplicates do not exist in the tree.Analyse: We can...
分类:
其他好文 时间:
2015-07-29 21:16:40
阅读次数:
168
Given a binary tree, return the inorder traversal of its nodes' values.
For example:
Given binary tree {1,#,2,3},
1
2
/
3
return [1,3,2].
Note: Recursive solutio...
分类:
其他好文 时间:
2015-07-28 10:51:19
阅读次数:
108