1 typedef enum 2 { 3 SubTree, //子树 4 Thread //线索 5 }NodeFlag; 6 7 typedef struct ThreadTree 8 { 9 DATA data; ...
分类:
编程语言 时间:
2015-04-25 22:33:21
阅读次数:
176
BNU的基础题,数据结构的基础题,顺便搞下.二叉树是一种常用的数据结构。我们可以用大写的英文字母表示二叉树的节点。如下: B / \ / \ C A \ \ ...
分类:
其他好文 时间:
2015-04-25 18:03:20
阅读次数:
188
对于一棵二叉树T,我们可以递归定义它的先序遍历,中序遍历,后序遍历:
??
1、先序遍历 ( PreOrder(T) = T的根节点 + PreOrder(T的左子树) + PreOrder(T的右子树) )
2、中序遍历 ( InOrder(T) = InOrder(T的左子树) + T的根节点 + InOrder(T的右子树) )
3、后...
分类:
其他好文 时间:
2015-04-23 11:02:56
阅读次数:
120
problem:
Given inorder and postorder traversal of a tree, construct the binary tree.
Note:
You may assume that duplicates do not exist in the tree.
Hide Tags
Tree Array Depth-first...
分类:
其他好文 时间:
2015-04-23 09:35:14
阅读次数:
157
problem:
Given preorder and inorder traversal of a tree, construct the binary tree.
Note:
You may assume that duplicates do not exist in the tree.
Hide Tags
Tree Array Depth-first
...
分类:
其他好文 时间:
2015-04-22 11:49:15
阅读次数:
122
实现功能:同splay区间反转 1(基于BZOJ3223 文艺平衡树)这次改用了一个全新的模板(HansBug:琢磨了我大半天啊有木有),大大简化了程序,同时对于splay的功能也有所完善这里面没有像一般二叉排序树那样子用一个参量进行排序,而是直接以中序遍历来构建了一个普通的二叉树(当然也可以把每个...
分类:
编程语言 时间:
2015-04-20 22:13:13
阅读次数:
175
给定一棵树的先序遍历和中序遍历结果,重新构建这棵树。解决思路:1. 从先序遍历序列中找到root节点2. 在中序遍历序列中找到root出现的下标位置,记为root_iter. root_iter左边的为左子树的中序遍历序列,长度为lTreeSize, 右边为右子树的中序遍历序列。3. 先序遍历序列中...
分类:
其他好文 时间:
2015-04-17 20:09:25
阅读次数:
118
problem:
Two elements of a binary search tree (BST) are swapped by mistake.
Recover the tree without changing its structure.
Note:
A solution using O(n) space is pretty straight forwar...
分类:
其他好文 时间:
2015-04-17 18:14:49
阅读次数:
148
中序遍历按照“左孩子-根结点-右孩子”的顺序进行访问。1.递归实现void inOrder(BinTree* root){ if(root!=NULL) { inOrder(root->lchild); coutdata; inOrder(root->rchild); }}2...
分类:
其他好文 时间:
2015-04-16 19:28:09
阅读次数:
156
problem:
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: Rec...
分类:
其他好文 时间:
2015-04-16 10:27:18
阅读次数:
119