#include <bits/stdc++.h>
#define pb push_back
#define mem(a,b) memset(a,b,sizeof a)
using namespace std;
typedef long long ll;
const int INF=0x3f3f3f3f;
string m,h;
void tree(int root,int b,int e)//b,e是中序的下标,root是后序的下标
{
//cout<<root;
if(b>e) return ;
int t=b;
while(t<e&&h[root]!=m[t]) t++;
cout<<h[root];
tree(root-(e-t+1),b,t-1);
tree(root-1,t+1,e);
return ;
}
int main()
{
// freopen("D:\\LYJ.txt","r",stdin);
cin>>m>>h;
int l=h.length();
tree(l-1,0,l-1);
return 0;
}
根据中序遍历后序遍历输出先序遍历
最新推荐文章于 2024-05-11 15:31:22 发布