当前位置:网站首页>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;
}
边栏推荐
- LVS load balancing cluster deployment - Dr direct routing mode
- JD home programmers delete databases and run away. Talk about binlog, the killer of MySQL data backup
- MySQL advanced (Advanced) SQL statement
- VBA, JSON interpretation, table structure -json string conversion
- Common tips
- Local MySQL forgot the password modification method (Windows)
- Definition and method of string
- [Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 10
- (August 10, 2021) web crawler learning - Chinese University ranking directed crawler
- Guava ImmutableSet. Builder source code analysis, shift original code, complement code, reverse code review
猜你喜欢

Introduction of network security research direction of Shanghai Jiaotong University
![[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 8](/img/16/33f5623625ba817e6e022b5cb7ff5d.jpg)
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 8

01. Basics - MySQL overview

JD home programmers delete databases and run away. Talk about binlog, the killer of MySQL data backup

Single spa, Qiankun, Friday access practice
![[the way of programmer training] - 2 Perfect number calculation](/img/fd/4bb8560f601daddaa8895f20215be4.jpg)
[the way of programmer training] - 2 Perfect number calculation

DDS-YYDS

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

IPv6 experiment
![Entitas learning [3] multi context system](/img/f9/a3ce86ff2121dd1043305b7e834cc5.jpg)
Entitas learning [3] multi context system
随机推荐
Definition and method of string
netstat
2020 Summary - Magic year, magic me
Review of week 278 of leetcode II
Map container
TCP fast retransmission sack mechanism
Number and math classes
QQ group administrators
Install freeradius3 in the latest version of openwrt
. Does net 4 have a built-in JSON serializer / deserializer- Does . NET 4 have a built-in JSON serializer/deserializer?
How to use "bottom logic" to see the cards in the world?
Source code analysis of the implementation mechanism of multisets in guava class library
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 8
Guava ImmutableSet. Builder source code analysis, shift original code, complement code, reverse code review
Reptile learning winter vacation series (2)
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 7
Automatic translation between Chinese and English
Experiment 7. IPv6
World document to picture
Openssl3.0 learning 20 provider KDF