当前位置:网站首页>Uva536 binary tree reconstruction tree recovery
Uva536 binary tree reconstruction tree recovery
2022-07-04 12:25:00 【Harmful Poems】
Enter the sequence of preorder traversal and middle order traversal of a binary tree , Output its post order traversal sequence .
#include<bits/stdc++.h>
using namespace std;
string preorder,inorder;
void postorder(string pre,string in){
if(pre.size() <= 0){
return ;
}
int len = 0;
len = in.find(pre[0]);
postorder(pre.substr(1,len),in.substr(0,len));
postorder(pre.substr(len+1).in.substr(len+1));
cout<<pre[0];
}
int mian(){
while(cin>>preorder>>inorder){
postorder(preorder,inorder);
cout<<endl;
}
return 0;
}
#include<bits/stdc++.h>
using namespace std;
string preorder,inorder;
void postorder(int l1,int l2,int n){
if(n <= 0){
return ;
}
int len = 0;
int len = inorder.find(preorder[l1]) - l2;
postorder(l1+1,l2,len);
postorder(l1+len+1,l2+len+1,n-len-1);
cout<<preorder[l1];
}
int mian(){
while(cin>>preorder>>inorder){
int len = preorder.size();
postorder(0,0,len);// Preamble start subscript , Middle order start subscript , length
cout<<endl;
}
return 0;
}
边栏推荐
- Googgle guava ImmutableCollections
- Recommend a cool geospatial data visualization tool with low code
- The detailed installation process of Ninja security penetration system (Ninjitsu OS V3). Both old and new VM versions can be installed through personal testing, with download sources
- C language compilation process
- Bottom Logic -- Mind Map
- 03_ Armv8 instruction set introduction load and store instructions
- 2020 Summary - Magic year, magic me
- How to judge the advantages and disadvantages of low code products in the market?
- Application of slice
- Here, the DDS tutorial you want | first experience of fastdds - source code compilation & Installation & Testing
猜你喜欢
TCP fast retransmission sack mechanism
Day01 preliminary packet capture
Ultimate bug finding method - two points
Process communication and thread explanation
Practical dry goods: deploy mini version message queue based on redis6.0
Foreach (system.out:: println) usage
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 24
[solve the error of this pointing in the applet] SetData of undefined
Properties and methods of OS Library
Reptile learning winter vacation series (2)
随机推荐
QQ get group member operation time
Btrace tells you how to debug online without restarting the JVM
Data communication and network: ch13 Ethernet
priority_ queue
Definition and method of string
LxC shared directory addition and deletion
MYCAT middleware installation and use
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 18
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 24
OSI seven layer model & unit
Enter the smart Park, and change begins here
Process communication and thread explanation
(August 9, 2021) example exercise of air quality index calculation (I)
LxC shared directory permission configuration
[directory] search
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 11
Tableau makes data summary after linking the database, and summary exceptions occasionally occur.
Exceptions and exception handling
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 17
TCP fast retransmission sack mechanism