当前位置:网站首页>1086 tree traversals again (25 points)
1086 tree traversals again (25 points)
2022-07-03 04:56:00 【vs5】
Stacking is the preamble , Out of the stack is the middle order
#include <iostream>
#include <vector>
using namespace std;
const int N = 50;
int stk[N],top,f;
vector<int>pre,in;
// Stacking is the preamble , Out of the stack is the middle order
void dfs(int preL,int preR,int inL,int inR)
{
if(preL > preR) return ;
int k = inL;
while(in[k] != pre[preL]) k ++;
dfs(preL + 1,preL + k - inL,inL,k - 1);
dfs(preL + 1 + k - inL,preR,k + 1,inR);
if(f != 0) cout << ' ';
cout << pre[preL];f = 1;
}
int main()
{
int n,x,cnt = 0;
string s;
cin >> n;
while(cnt != n)
{
cin >> s;
if(s[1] == 'u')
{
cin >> x;
stk[ ++ top] = x;
pre.push_back(x);
}
else in.push_back(stk[top --]),cnt ++;
}
dfs(0,n - 1,0,n - 1);
return 0;
} 边栏推荐
- 2022-02-12 daily clock in: problem fine brush
- First + only! Alibaba cloud's real-time computing version of Flink passed the stability test of big data products of the Institute of ICT
- 文献阅读_基于多模态数据语义融合的旅游在线评论有用性识别研究(中文文献)
- 5-36v input automatic voltage rise and fall PD fast charging scheme drawing 30W low-cost chip
- Market status and development prospect prediction of the near infrared sensor industry of the global Internet of things in 2022
- Cross platform plug-in flutter for displaying local notifications_ local_ notifications
- Uipath practice (08) - selector
- Notes | numpy-08 Advanced index
- Silent authorization login and registration of wechat applet
- I've seen a piece of code in the past. I don't know what I'm doing. I can review it when I have time
猜你喜欢

Valentine's day limited withdrawal guide: for one in 200 million of you

SSM framework integration

ZABBIX monitoring of lamp architecture (3): zabbix+mysql (to be continued)

The simple problem of leetcode: dismantling bombs

On typescript and grammar

论文阅读_清华ERNIE

Analysis of proxy usage of ES6 new feature

Handler understands the record
![[set theory] relational representation (relational matrix | examples of relational matrix | properties of relational matrix | operations of relational matrix | relational graph | examples of relationa](/img/a9/92059db74ccde03b84c69dfce35b37.jpg)
[set theory] relational representation (relational matrix | examples of relational matrix | properties of relational matrix | operations of relational matrix | relational graph | examples of relationa

Without 50W bride price, my girlfriend was forcibly dragged away. What should I do
随机推荐
Review the configuration of vscode to develop golang
MPM model and ab pressure test
Introduction to message queuing (MQ)
Mount NFS in kubesphere
The simple problem of leetcode: dismantling bombs
并发操作-内存交互操作
[research materials] 2021 annual report on mergers and acquisitions in the property management industry - Download attached
ZABBIX monitoring of lamp architecture (2): ZABBIX basic operation
The reason why the entity class in the database is changed into hump naming
Cross platform plug-in flutter for displaying local notifications_ local_ notifications
Why does I start with =1? How does this code work?
[Yu Yue education] basic reference materials of interchangeability and measurement technology of Zhongyuan Institute of Technology
Interface frequency limit access
2022-02-11 daily clock in: problem fine brush
document. The problem of missing parameters of referer is solved
50 practical applications of R language (36) - data visualization from basic to advanced
论文阅读_中文医疗模型_ eHealth
"Niuke brush Verilog" part II Verilog advanced challenge
逆袭大学生的职业规划
7. Integrated learning