已知前序中序 建立二叉树并以后序输出
# include <iostream>
# include <cstdio>
# include <cmath>
# include <cctype>
# include <map>
# include <string>
# include <stack>
using namespace std;
typedef struct treenode
{
char data;
treenode* lchild;
treenode* rchild;
}tn, * ptn;
int cnt=0;
ptn creatree(string s1, string s2);
void postorder(ptn t);
int findl(char key, string s);
int main()
{
string s1, s2;
cin >> s1 >> s2;
ptn head = creatree(s1,s2);
postorder(head);
return 0;
}
ptn creatree(string s1,string s2)
{
if (!s1.length())return NULL;
ptn m = new tn;
char key = s1[0];
int len = s1.length();
m->data =key ;//根节点
int pos = findl(key, s2);
string a = s1.substr(1, pos);
string b = s2.substr(0, pos);
m->lchild = creatree(a, b);
a = s1.substr(pos+1, len-pos-1);
b = s2.substr(pos+1, len-pos);
m->