![](https://img-blog.csdnimg.cn/20201014180756780.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
二叉树
oinei
欢迎加入菜鸡交流群:697208008
博主QQ:1119116025
展开
-
二叉树
树:没有环的无向图,n个节点的树只有n-1条边 分为先序遍历(vlr),中序遍历(lvr),后序遍历(lrv)先序遍历(vlr) : A B D E F G C H I 中序遍历(lvr) : D B F E G A H I C 后序遍历(lrv) : D F G E B I H C A原创 2017-03-06 18:04:37 · 251 阅读 · 0 评论 -
hdu 1710 Binary Tree Traversals(二叉树:前中求后)
前:1 2 4 7 3 5 8 9 6 pre[] 中:4 7 2 1 8 5 9 3 6 in[]l , r 分别对应中序列(int[])的首地址和尾地址 i 对应中序遍历中的结点 rt 对应前序遍历中的结点 后序遍历(lrv)#include <iostream> #include <algorithm> #include <cstdio> #include <cstrin原创 2017-03-16 11:44:33 · 200 阅读 · 0 评论 -
PKU 2255 Tree Recovery(二叉树)
前中求后#include <iostream> #include <algorithm> #include <cstdio> #include <cstring> #include <map> #include <queue> #include <string> #include <set> #include <vector> using namespace std; const int N=27,原创 2017-03-16 17:10:07 · 210 阅读 · 0 评论 -
二叉树遍历模板 (前中求后、后中求前)
前中求后 #include &amp;lt;bits/stdc++.h&amp;gt; using namespace std; typedef long long ll; const int N=5e4+7,INF=0x3f3f3f3f; int in[N],pre[N]; int n,k; void dfs(int l,int r,int rt) { int i; for(i=l;in[i]...原创 2018-07-08 14:22:35 · 283 阅读 · 0 评论 -
二叉树遍历问题
给定二叉树的先序遍历和后序遍历,计算可能有几棵二叉树 Input 本问题有多组测试数据,第一行是测试数据的组数n,紧接着是n组测试数据。每组测试数据有两行,分别表示二叉树的先序遍历和后序遍历,每个结点用大写字母表示,输入保证数据是正确的。 Output 对于每一组输入,对应的输出只有一行,即符合给定的先序遍历和后序遍历这样条件的二叉树的棵数。 Sample Input 1 AB...原创 2018-07-13 15:53:01 · 334 阅读 · 0 评论