雕刻时光

just do it……nothing impossible
随笔 - 547, 文章 - 0, 评论 - 82, 阅读 - 86万
  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

随笔分类 -  树遍历 相关

摘要:转自http://www.cnblogs.com/coder2012/p/3330311.htmlhttp://blog.sina.com.cn/s/blog_6776884e0100ohvr.html这篇在大体上比较清晰简单的描述了概念,比较通俗易懂B-tree B-tree,B是balance,一般用于数据库的索引。使用B-tree结构可以显著减少定位记录时所经历的中间过程,从而加快存取速度。而B+tree是B-tree的一个变种,大名鼎鼎的MySQL就普遍使用B+tree实现其索引结构。 那数据库为什么使用这种结构? 一般来说,索引本身也很大,不可能全部存储在内存中,因此索引往往以索.. 阅读全文

posted @ 2013-11-26 10:24 huhuuu 阅读(2545) 评论(0) 推荐(0) 编辑

摘要:题目列表:1. 求二叉树中的节点个数 DFS遍历时记录点的个数2. 求二叉树的深度 DFS遍历时记录点的最大3. 前序遍历,中序遍历,后序遍历 三种DFS4.分层遍历二叉树(按层次从上往下,从左往右) BFS5. 将二叉查找树变为有序的双向链表 先建树,在中序遍历即可//1//4 2 1 0 0 3 0 0 6 5 0 0 7 0 0#includestruct Tree{ int v; Tree *left,*right;}*rhead;void build(Tree *head){ int temp; scanf("%d",&temp); if(te... 阅读全文

posted @ 2013-10-27 22:07 huhuuu 阅读(298) 评论(0) 推荐(0) 编辑

摘要:先判断两个点是否在树中,若不是则直接就找不到若在树中,则DFS搜索连个点所在的路径,搜到了两个路径,在找两个路径最开始的相同点,也就是最近祖先结点PS:吐槽,题目数据中结点会有相同的情况,所以用前驱寻找时会出现死循环!注意先#include#include#includeusing namespace std;struct TREE{ int v; TREE *left,*right;}*rhead;int shu[10009],all=0;void bulid(TREE *head){ int temp; scanf("%d",&temp); if(temp==. 阅读全文

posted @ 2013-10-27 21:05 huhuuu 阅读(810) 评论(0) 推荐(0) 编辑

摘要:http://ac.jobdu.com/problem.php?pid=1520题目描述:输入两颗二叉树A,B,判断B是不是A的子结构。先建树,为了后面匹配时提高速度,每个结点做一个索引然后枚举A中的结点是否与B的树根相同,若相同,则遍历B的同时遍历A,判断是否相似#includestruct Tree{ int v; Tree *left,*right;}* Atree_p[1099],* Btree_p[1099];int n,m;int nodeL,nodeR;void build(Tree *thead,int num,int v){ thead->v=v; i... 阅读全文

posted @ 2013-10-23 21:43 huhuuu 阅读(696) 评论(0) 推荐(0) 编辑

摘要:http://pat.zju.edu.cn/contests/pat-a-practise/1043给予N个数字组成二叉搜索树,判断这个数列是否由先序遍历得出或是镜像先序遍历得出,若是则输出相应的后续遍历或是镜像后续遍历分析:镜像先序遍历其实就是 先访问祖先,再访问右子树,再左子树镜像后续遍历就是先访问右子树,再左子树,在祖先#includestruct tree{ int v; tree *left,*right;};int shu[1099];int pre[1099];int post[1099];int step;void bulid(tree* head,int v){ ... 阅读全文

posted @ 2013-10-05 11:27 huhuuu 阅读(290) 评论(0) 推荐(0) 编辑

摘要://题目 通过后续遍历 中序遍历 得出一棵树 ,然后按树的层次遍历打印PS:以前对于这种用指针的题目是比较头痛的,现在做了一些链表操作后,感觉也不难先通过后续中序建一棵树,然后通过BFS遍历这棵树提供测试样例44 1 3 22 3 1 41010 7 6 9 8 5 4 1 3 27 10 6 2 5 9 8 3 1 4//题目 通过后续遍历 中序遍历 得出一棵树 ,然后按树的层次遍历打印#include#include#includeusing namespace std;int back[90];int mid[90];int n;struct data{ int v; int... 阅读全文

posted @ 2013-09-30 18:49 huhuuu 阅读(904) 评论(0) 推荐(0) 编辑

摘要:先将数据插入到一颗二叉树中,再中序遍历该树View Code #include<stdio.h>#include<string.h>#include<iostream>using namespace std;struct data{ int l,m,r;}node[100090];int add,ok=0;;void insert(int c,int root){ if(c>node[root].m)//óò { if(node[root].r==-1) { node[root].r=add; node[... 阅读全文

posted @ 2011-09-02 21:34 huhuuu 阅读(397) 评论(1) 推荐(0) 编辑

点击右上角即可分享
微信分享提示