当前位置:网站首页>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;
} 边栏推荐
- Uipath practice (08) - selector
- Analysis of proxy usage of ES6 new feature
- Use Sqlalchemy module to obtain the table name and field name of the existing table in the database
- C language self-made Games: Sanzi (tic tac toe chess) intelligent chess supplement
- Concurrent operation memory interaction
- [Yu Yue education] basic reference materials of interchangeability and measurement technology of Zhongyuan Institute of Technology
- 论文阅读_清华ERNIE
- Actual combat 8051 drives 8-bit nixie tube
- Web security - CSRF (token)
- Three representations of signed numbers: original code, inverse code and complement code
猜你喜欢

Interface frequency limit access

Number of uniform strings of leetcode simple problem

STM32 reverse entry

Kept hot standby and haproxy

Without 50W bride price, my girlfriend was forcibly dragged away. What should I do
![[tools run SQL blind note]](/img/c3/86db4568b221d2423914990a88eec2.png)
[tools run SQL blind note]

Preparation for school and professional cognition

Basic use of Metasploit penetration testing framework

Source insight garbled code solution

The principle is simple, but I don't know how to use it? Understand "contemporaneous group model" in one article
随机推荐
Apache MPM model and ab stress test
[research materials] 2021 annual report on mergers and acquisitions in the property management industry - Download attached
并发操作-内存交互操作
The usage of micro service project swagger aggregation document shows all micro service addresses in the form of swagger grouping
Hire cashier (differential constraint)
"Niuke brush Verilog" part II Verilog advanced challenge
Shell script -- condition judgment
The current market situation and development prospect of the global gluten tolerance test kit industry in 2022
Mobile terminal - uniapp development record (public request encapsulation)
Cross platform plug-in flutter for displaying local notifications_ local_ notifications
Leetcode simple question: the key with the longest key duration
ZABBIX monitoring of lamp architecture (2): ZABBIX basic operation
2022-02-11 daily clock in: problem fine brush
Without 50W bride price, my girlfriend was forcibly dragged away. What should I do
[SQL injection] joint query (the simplest injection method)
On typescript and grammar
The process of browser accessing the website
第十九届浙江省 I. Barbecue
[set theory] relationship properties (symmetry | symmetry examples | symmetry related theorems | antisymmetry | antisymmetry examples | antisymmetry theorems)
Notes | numpy-07 Slice and index