当前位置:网站首页>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;
} 边栏推荐
- Leetcode simple question: check whether two string arrays are equal
- Retirement plan fails, 64 year old programmer starts work again
- Truncated sentences of leetcode simple questions
- Day 51 - tree problem
- Analysis of proxy usage of ES6 new feature
- Mobile terminal - uniapp development record (public request encapsulation)
- Career planning of counter attacking College Students
- [USACO 2009 Dec S]Music Notes
- 2022-02-12 daily clock in: problem fine brush
- 2022-02-11 daily clock in: problem fine brush
猜你喜欢

Introduction to message queuing (MQ)

带有注意力RPN和多关系检测器的小样本目标检测网络(提供源码和数据及下载)...

Introduction to JVM principle

Analysis of proxy usage of ES6 new feature

data2vec! New milestone of unified mode

MC Layer Target

The simple problem of leetcode: dismantling bombs

Prepare for 2022 and welcome the "golden three silver four". The "summary of Android intermediate and advanced interview questions in 2022" is fresh, so that your big factory interview can go smoothly

I stepped on a foundation pit today

5-36v input automatic voltage rise and fall PD fast charging scheme drawing 30W low-cost chip
随机推荐
JDBC database operation
Day 51 - tree problem
Market status and development prospects of the global automatic tea picker industry in 2022
Prepare for 2022 and welcome the "golden three silver four". The "summary of Android intermediate and advanced interview questions in 2022" is fresh, so that your big factory interview can go smoothly
Esp32-c3 learning and testing WiFi (II. Wi Fi distribution - smart_config mode and BlueIf mode)
1119 pre- and post order traversals (30 points)
MediaTek 2023 IC written examination approved in advance (topic)
Analysis of proxy usage of ES6 new feature
Leetcode simple question: check whether the string is an array prefix
[tools run SQL blind note]
Cross platform plug-in flutter for displaying local notifications_ local_ notifications
M1 Pro install redis
data2vec! New milestone of unified mode
Leetcode simple problem delete an element to strictly increment the array
On typescript and grammar
Uipath practice (08) - selector
MPM model and ab pressure test
Messy change of mouse style in win system
Learn to use the idea breakpoint debugging tool
【工具跑SQL盲注】