只知道先序序列和后序序列是无法求出唯一的树,所以不做讨论。
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
struct BinaryTreeNode
{
char c;
BinaryTreeNode *lchild, *rchild;
BinaryTreeNode()
{
lchild = NULL, rchild = NULL;
}
};
struct BinaryTreeNode *root1,*root2;
char preorder[100], inorder[100], postorder[100];
void preSearch(BinaryTreeNode *root) //先序遍历树
{
if(root != NULL)
{
printf("%c", root->c);
preSearch(root->lchild);
preSearch(root->rchild);
}
return ;
}
void midSearch(BinaryTreeNode *root) //中序遍历树
{
if(root != NULL)
{
midSearch(root->lchild);
printf("%c", root->c);
midSearch(root->rchild);
}
return ;
}
void postSearch(BinaryTreeNode *root) //后序遍历树
{
if(root != NULL)
{
postSearch(root->lchild);
postSearch(root->rchild);
printf("%c&