当前位置:网站首页>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;
} 边栏推荐
- [research materials] annual report of China's pension market in 2021 - Download attached
- Shell script Basics - basic grammar knowledge
- 论文阅读_中文医疗模型_ eHealth
- "Niuke brush Verilog" part II Verilog advanced challenge
- [research materials] 2021 annual report on mergers and acquisitions in the property management industry - Download attached
- 联发科技2023届提前批IC笔试(题目)
- Notes | numpy-11 Array operation
- Market status and development prospect prediction of the global forward fluorescent microscope industry in 2022
- The simple problem of leetcode: dismantling bombs
- @RequestMapping
猜你喜欢

LVS load balancing cluster of efficient multi-purpose cluster (NAT mode)

Silent authorization login and registration of wechat applet

Network security textual research recommendation

Web security - CSRF (token)

Introduction to message queuing (MQ)

关于开学的准备与专业认知

Oracle SQL table data loss

Leetcode simple question: check whether the string is an array prefix

Learning practice: comprehensive application of cycle and branch structure (I)

Thesis reading_ Tsinghua Ernie
随机推荐
Without 50W bride price, my girlfriend was forcibly dragged away. What should I do
The current market situation and development prospect of the global gluten tolerance test kit industry in 2022
MediaTek 2023 IC written examination approved in advance (topic)
Interface frequency limit access
On typescript and grammar
The programmer resigned and was sentenced to 10 months for deleting the code. JD came home and said that it took 30000 to restore the database. Netizen: This is really a revenge
Notes | numpy-10 Iterative array
Learning record of arouter principle
SSM framework integration
LVS load balancing cluster of efficient multi-purpose cluster (NAT mode)
Introduction to JVM principle
Flutter monitors volume to realize waveform visualization of audio
I stepped on a foundation pit today
Cross platform plug-in flutter for displaying local notifications_ local_ notifications
document. The problem of missing parameters of referer is solved
Market status and development prospect prediction of global neutral silicone sealant industry in 2022
[research materials] annual report of China's pension market in 2021 - Download attached
First + only! Alibaba cloud's real-time computing version of Flink passed the stability test of big data products of the Institute of ICT
Current market situation and development prospect prediction of global direct energy deposition 3D printer industry in 2022
[luatos sensor] 2 air pressure bmp180