Altered Structure

This commit is contained in:
e2hang
2025-08-31 10:21:06 +08:00
parent daeec35f97
commit e162486df1
6 changed files with 53 additions and 0 deletions

View File

@@ -0,0 +1,21 @@
#include <iostream>
#include <string>
using namespace std;
void build(string& _pre, string& _in, int pre_front, int pre_end, int in_front, int in_end){
if (pre_front > pre_end) return;
char root;
root = _pre[pre_front];
int k = _in.find(root, in_front);//<2F><>in_front<6E><74>ʼ
int leftsize = k - in_front;
build(_pre, _in, pre_front + 1, pre_front + leftsize, in_front, k - 1);
build(_pre, _in, pre_front + leftsize + 1 , pre_end, k + 1, in_end);
cout << root << " ";
}
int main(){
string pre, in;
cin >> pre >> in;
build(pre, in, 0, pre.size() - 1, 0, in.size() - 1);
return 0;
}