文章
9
粉丝
126
获赞
8
访问
24.5k
#include <bits/stdc++.h>
using namespace std;
typedef struct node{
char data;
struct node *lchild,*rchild;
}node,*Tree;
void createTree(Tree &T,string pre,string in){
T=new node;
T->lchild=NULL;T->rchild=NULL;
T->data=pre[0];
if(pre.size()==1) return;
int mid=in.find(pre[0]);
if(mid!=0){
createTree(T->lchild,pre.substr(1,mid+1),in.substr(0,mid));
}
if(mid!=in.size()-1){
createTree(T->rchild,pre.substr(mid+1),in.substr(mid+1));
}
}
void postOrder(Tree T){
if(T!=NULL){
postOrder(T->lchild);
postOrder(T->rchild);
&...
登录后发布评论
应该是
if(mid!=0){
createTree(T->lchild,pre.substr(1,mid),in.substr(0,mid));
}