博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
1020. Tree Traversals (25)
阅读量:4072 次
发布时间:2019-05-25

本文共 947 字,大约阅读时间需要 3 分钟。

1020. Tree Traversals (25)

#include 
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;struct TreeNode { int val; struct TreeNode *left; struct TreeNode *right; TreeNode(int x) : val(x), left(NULL), right(NULL) { }};TreeNode *create(vector
pre,vector
in,int first,int last,int &curRoot){ if (first>last){ curRoot++; return NULL; } TreeNode *p = new TreeNode(pre[curRoot]); auto it = find(in.begin()+first,in.begin()+last+1,pre[curRoot]); int pos = (int)(it- in.begin()); p->right =create(pre, in, pos+1, last, --curRoot); p->left = create(pre, in, first,pos-1, --curRoot); return p;}int main(){ int n; scanf("%d",&n); vector
post(n),in(n); for (int i=0; i
ans; queue
q; if(p) q.push(p); while (!q.empty()) { p = q.front(); q.pop(); ans.push_back(p->val); if(p->left) q.push(p->left); if(p->right) q.push(p->right); } for (int i=0; i

转载地址:http://pmhji.baihongyu.com/

你可能感兴趣的文章
javascript传参字符串 与引号的嵌套调用
查看>>
swiper插件的的使用
查看>>
layui插件的使用
查看>>
JS牛客网编译环境的使用
查看>>
9、VUE面经
查看>>
Golang 数据可视化利器 go-echarts ,实际使用
查看>>
mysql 跨机器查询,使用dblink
查看>>
mysql5.6.34 升级到mysql5.7.32
查看>>
dba 常用查询
查看>>
Oracle 异机恢复
查看>>
Oracle 12C DG 搭建(RAC-RAC/RAC-单机)
查看>>
Truncate 表之恢复
查看>>
Oracle DG failover 后恢复
查看>>
mysql 主从同步配置
查看>>
为什么很多程序员都选择跳槽?
查看>>
mongdb介绍
查看>>
mongdb在java中的应用
查看>>
Yotta企业云盘更好的为媒体广告业服务
查看>>
Yotta企业云盘助力科技行业创高峰
查看>>
Yotta企业云盘更好地为教育行业服务
查看>>