文章
82
粉丝
344
获赞
28
访问
698.2k
#include <iostream>
#include <string.h>
using namespace std;
typedef struct node{
char data;
struct node *lchild;
struct node *rchild;
}BiNode,*BiTree;
char pre[1005];
char mid[1005];
BiTree build(char *pre,char *mid,int l1,int r1,int l2,int r2){
if(l1>r1) return NULL;//递归边界
int k=0;
for(int i=l2;i<=r2;i++){
if(mid[i]==pre[l1]){
k=i;
break;
}
}
BiTree t=new node;
t->data=pre[l1];
t->lchild=t->rchild=NULL;
t->lchild=build(pre,mid,l1+1,l1+k-l2,l2,k-1);
t->rchild=build(pre,mid,l1+k-l2+1,r1,k+1,r2);
&nb...
登录后发布评论
暂无评论,来抢沙发