The first and middle order traversal sequences of a known binary tree are output.

Source: Internet
Author: User

Description
The first and middle traversal sequences of the input binary tree are output.
Input
The first line is used to input the first sequential traversal sequence of a binary tree;
The second line is the central traversal sequence of the binary tree.
Output
Output the post-order traversal sequence of the binary tree.
Sample Input
ABDCEF
BDAECF
Sample output
DBEFCA

# Include
 
  
# Include
  
   
# Define MAX 50 + 3 using namespace std; typedef char Elem_Type; typedef struct BiTree {Elem_Type data; // data struct BiTree * Lchild; // left child struct BiTree * Rchild; // right child} BiTree; // The length of the array where the element to be searched is int Search_Num (Elem_Type num, Elem_Type * array, int len) {for (int I = 0; I
   
    
Data = * 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) // post-order traversal {if (root! = NULL) {PostOrderTraverse (root-> Lchild); PostOrderTraverse (root-> Rchild); cout <
    
     
Data ;}} int main (void) {Elem_Type * preorder = new Elem_Type [MAX]; // pre-order Elem_Type * inorder = new Elem_Type [MAX]; // medium order cin> preorder; cin> inorder; BiTree * root = Resume_BiTree (preorder, inorder, strlen (inorder); PostOrderTraverse (root); cout <
     
      

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.