文章
75
粉丝
0
获赞
147
访问
8.7k
#include <bits/stdc++.h>
using namespace std;
typedef struct node{
char data;
node *left,*right;
}*Tree;
void CreateTree(Tree &t,string pre,string in){
//每次确认一个根
if(pre == ""){
t = nullptr;
return;
}
t = new node();
t->data = pre[0];
//把中序的分两半
int index = in.find(pre[0]);
string leftIn = in.substr(0,index);
string rightIn = in.substr(index+1);
//把先序的也分两半
string leftPre = pre.substr(1,index);
string rightPre = pre.substr(index+1);
//递归
CreateTree(t->left,leftPre,leftIn);
CreateTree(t->right,rightPre,rightIn);
}
void Post(Tree t){
if(t != nullptr){
Post(t->left);
P...
登录后发布评论
暂无评论,来抢沙发