PAT L2-006【二叉树中序后序构造树】
来源:互联网 发布:js 二维数组匹配 编辑:程序博客网 时间:2024/04/27 08:30
#include<bits/stdc++.h>using namespace std;typedef long long LL;struct BT{int w;BT *L;BT *R;};BT* Creat(int *post,int *in,int n){BT* p;for(int i=0;i<n;i++){if(post[n-1]==in[i]){p=(BT*)malloc(sizeof(BT));p->w=in[i];p->L=Creat(post,in,i);p->R=Creat(post+i,in+i+1,n-(i+1));return p;}}return NULL;}int main(){int post[35],in[35],n;BT* root;scanf("%d",&n);for(int i=0;i<n;i++)scanf("%d",&post[i]);for(int i=0;i<n;i++)scanf("%d",&in[i]);root=Creat(post,in,n);queue<BT*>q;q.push(root);bool flag=false;while(!q.empty()){BT* now=q.front();q.pop();if(flag) printf(" ");printf("%d",now->w);if(now->L) q.push(now->L);if(now->R) q.push(now->R);flag=true;}return 0;}
1 0
- PAT L2-006【二叉树中序后序构造树】
- PAT L2-011. 玩转二叉树
- pat L2-011. 玩转二叉树@
- PAT L2-011 玩转二叉树
- PAT L2-011. 玩转二叉树
- L2-4. 这是二叉搜索树吗? PAT
- pat 天梯 L2-4. 这是二叉搜索树吗?
- PAT - L2-011. 玩转二叉树(分冶)
- PAT L2-006. 树的遍历(二叉树重构)
- PAT L2-004. 这是二叉搜索树吗?
- PAT L2-004. 这是二叉搜索树吗?
- PAT L2-004. 这是二叉搜索树吗?
- PAT--L2-004. 这是二叉搜索树吗?
- PAT 两个二叉树的模拟题 L2-004,L2-011
- PAT L2-006 树的遍历
- L2-006&&L2-011二叉树层遍历
- PAT L2-011.玩转二叉树(数据结构,二叉链表)
- L2-011. 玩转二叉树-PAT团体程序设计天梯赛GPLT
- java并发与多线程总结
- Tensorflow在Android上的应用(Windows、Mac、Linux)
- 在angular-cli项目中使用Scss和Pug(Jade)模板引擎
- 使用Ecplise git commit时出现"There are no stages files"
- python入门(四)
- PAT L2-006【二叉树中序后序构造树】
- 计算机组成原理学习1: C/C++编译器中字节对齐的原理
- linux网络编程之用select方法实现io复用(基于udp)
- 逆元-洛谷P1641 [SCOI2010]生成字符串
- Java反射机制
- SQL 循环遍历结果集
- kuangbin1(上)
- 【第18题】360校园招聘2015届技术类笔试题
- 搭建Eclipse开发环境