Question #60485

below shows the postfix epression. Draw a binary tree of abc * + de * f + g +

and find the following
i.infix expression

ii.prefix expression

From the traverssl of predorder , inorder and postorder as above write down the c++ statement for each

i.predorder function
ii.inorder function
1

Expert's answer

2016-06-23T08:48:03-0400

Answer on Question #60485, Programming & Computer Science / C++

Question:

below shows the postfix expression. Draw a binary tree of abc * + de * f + g + and find the following

i. infix expression

ii. prefix expression

From the traversal of predorder, inorder and postorder as above write down the c++ statement for each

i. predorder function

ii. inorder function

Solution:

i. Infix: (a + (b * c)) ? ((d * e) + f) + g)

ii. Prefix: ? + a * b c + + * d e f g



Figure 1. Expression tree

i.predorder function:


void Preorder(tree *root) {
    if(root == nullptr) return;
    cout << root->value << " ";
    Preorder(root->left);
    Preorder(root->right);
}


ii.inorder function:


void Inorder(tree *root) {
    if(root == nullptr) return;
    Inorder(root->left);
    cout << root->value << " ";
    Inorder(root->right);
}


https://www.AssignmentExpert.com

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!
LATEST TUTORIALS
APPROVED BY CLIENTS