struct node
{
char data;
struct node * l, *r;
};
struct node * build(int l, char xian[55], char zhong[55])//先序+中序还原二叉树
{
int i;
struct node * t;
if(l <= 0)
return NULL;
t = (struct node *)malloc(sizeof(struct node));
t->data = xian[0];
for(i = 0; i < l; i++)
{
if(zhong[i] == xian[0])
break;
}
t->l = build(i, xian+1,zhong);//数组名+ 1 数组【0】为原来数组【1】;
t->r = build(l - i - 1, xian + i + 1, zhong + 1 + i);
return t;
}
二叉树还原
猜你喜欢
转载自blog.csdn.net/weixin_41031401/article/details/81503270
今日推荐
周排行