Question
(Binary Tree) Given the pre-order traversal and in-order traversal of a binary tree, output the post-order traversal of the binary tree. Input format: line 1:
(Binary Tree)
Given the pre-order traversal and in-order traversal of a binary tree, output the post-order traversal of the binary tree.
Input format:
line 1: number of nodes
line 2: the pre-order traversal;
line 3: the in-order traversal.
note: The tree nodes are labeled 1, 2, ..., n
// Starting Code
#include
#include
typedefstructTreeNode{
intlabel;
TreeNode*left,*right;
}TreeNode;
usingnamespacestd;
intmain(){
intn;
cin>>n;
vector
for(inti=0;i
vector
for(inti=0;i
vector
//computeyourpostordertraversalinpostorder!
//outputthepostordertraversal
for(inti=0;i cout }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started