为什么每一轮递归都要输出a[x];这个子树的根,先左子树遍历,再右子树遍历,这样最后输出的结果为什么正好满足后序“左右根”,而不是按照递归程序运行的顺序输出右左根
#include<bits/stdc++.h>
#define ll long long
using namespace std;
string a,b;
void houxu(int x,int y,int p,int q){
if(x>y||p>q) return;
int i=b.find(a[x]);
houxu(x+1,x+i-p,p,i-1);
houxu(x+i-p+1,y,i+1,q);
cout<<a[x];
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
cin>>b>>a;
int l=a.length()-1;
houxu(0,l,0,l);
return 0;
}