对于一颗二叉树,可以根据先序遍历(后序遍历)和中序遍历重新还原出二叉树。
主要通过递归实现。
关键是找出对应左右子树的长度,之后传递先序遍历的开始节点、结束节点,中序遍历的开始节点、结束节点。
代码:
#include
using namespace std;
typedef struct tree{
int data;
struct tree *lchild;
struct ...
分类:
其他好文 时间:
2014-08-05 19:27:30
阅读次数:
224
lca。。。
排个序然后暴力保平安
_(:зゝ∠)_
#pragma comment(linker, "/STACK:102400000,102400000")
#include"cstdio"
#include"iostream"
#include"set"
#include"queue"
#include"string.h"
using namespace std;
#define...
分类:
其他好文 时间:
2014-08-05 19:25:00
阅读次数:
299
ext3.2 中的tree在IE中进行兼容性测试,遇到IE10时,无法点击,其他版本的IE(7、8、9、11)均正常。此bug是由于ext-all.js中的getAttributeNS方法不能兼容IE10出错引起的,下载了ext3.4,这里的getAttributeNS 被重写了,将3.4中的方法写...
分类:
其他好文 时间:
2014-08-05 18:52:29
阅读次数:
262
链接:http://acm.hdu.edu.cn/showproblem.php?pid=4786
题意:有N个节点(1 5),M条边(0 5),其中一部分边被染成了黑色,剩下的边是白色,问能不能建立一棵树,树中有斐波那契数个白色边。
思路:用克鲁斯卡尔建三次树,第一是用所有边建树,判断是否能建成一棵树,第二次用黑边建树,最多可以用到x条黑边(不成环),n-1-x就是最少需要用的白边的数量,第...
分类:
其他好文 时间:
2014-08-05 11:22:59
阅读次数:
209
Given a binary tree, determine if it is a valid binary search tree (BST).
Assume a BST is defined as follows:
The left subtree of a node contains only nodes with keys less than the node's key.Th...
分类:
其他好文 时间:
2014-08-05 09:43:39
阅读次数:
191
最近在项目中用到了,特地搬运过来。Kd-树 其实是K-dimension tree的缩写,是对数据点在k维空间中划分的一种数据结构。其实,Kd-树是一种平衡二叉树。举一示例:假设有六个二维数据点 = {(2,3),(5,4),(9,6),(4,7),(8,1),(7,2)},数据点位于二维空间中。为...
分类:
其他好文 时间:
2014-08-05 09:30:38
阅读次数:
321
题目:Given a binary tree, return the level order traversal of its nodes' values. (ie, from left to right, level by level).For example:Given binary tree....
分类:
编程语言 时间:
2014-08-05 05:18:28
阅读次数:
242
题目:Given a binary tree, return the bottom-up level order traversal of its nodes' values. (ie, from left to right, level by level from leaf to root).F....
分类:
编程语言 时间:
2014-08-05 05:18:08
阅读次数:
340
题目:Given a binary tree, return the zigzag level order traversal of its nodes' values. (ie, from left to right, then right to left for the next level ....
分类:
编程语言 时间:
2014-08-05 05:17:38
阅读次数:
311
题目: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....
分类:
编程语言 时间:
2014-08-05 05:17:28
阅读次数:
265