已知二叉树的先序遍历序列和中序遍历序列,输出该二叉树的后序遍历序列

题目描述
输入二叉树的先序遍历序列和中序遍历序列,输出该二叉树的后序遍历序列。
输入
第一行输入二叉树的先序遍历序列;
第二行输入二叉树的中序遍历序列。
输出
输出该二叉树的后序遍历序列。
示例输入
ABDCEF
BDAECF
示例输出
DBEFCA
#include 
#include 
#define MAX 50+3
using namespace std;
typedef char Elem_Type;
typedef struct BiTree
{
    Elem_Type data;//数据
    struct BiTree *Lchild;//左孩子
    struct BiTree *Rchild;//右孩子
}BiTree;      //要查找的元素  查找的地方    数组的长度
int Search_Num(Elem_Type num,Elem_Type *array,int len)
{
    for(int i=0; idata = *front;
    int index = Search_Num(*front,center,len);
    temp->Lchild = Resume_BiTree(front+1,center,index);
    temp->Rchild = Resume_BiTree(front+index+1,center+index+1,len-index-1);
    return temp;
}
void PostOrderTraverse(BiTree *root)//后序遍历
{
    if( root != NULL)
    {
        PostOrderTraverse(root->Lchild);
        PostOrderTraverse(root->Rchild);
        cout<data;
    }
}
int main(void)
{
    Elem_Type *preorder = new Elem_Type [MAX];//前序
    Elem_Type *inorder  = new Elem_Type [MAX];//中序
    cin>>preorder;cin>>inorder;
    BiTree *root = Resume_BiTree(preorder,inorder,strlen(inorder));
    PostOrderTraverse(root);
    cout<
已知二叉树的先序遍历序列和中序遍历序列,输出该二叉树的后序遍历序列_第1张图片

你可能感兴趣的:(数据结构和算法)