Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

How would you instead of hard coding the postfix expression(char postfix[] = 12+56*9*-;) in instead take input from a user? #include #include using namespace std;

How would you instead of hard coding the postfix expression(char postfix[] = "12+56*9*-";) in instead take input from a user?

#include #include

using namespace std; //Expression tree node struct ETree { char value; ETree* left, *right; }; bool isOperator(char c) { if (c == '+' || c == '-' || c == '*' || c == '/' || c == '^') return true; return false; } //Inorder traversal of the tree void inorder(ETree *t) { if(t) { inorder(t->left); printf("%c ", t->value); inorder(t->right); } } ETree* newNode(int v) { ETree *temp = new ETree; temp->left = temp->right = NULL; temp->value = v; return temp; }; //Tree for the expression ETree* constructTree(char postfix[]) { stack st; ETree *t, *t1, *t2; // Traverse through every character of // input expression for (int i=0; iright = t1; t->left = t2; // Add this subexpression to stack st.push(t); } } // only element will be root of expression // tree t = st.top(); st.pop(); return t; } // Driver program to convert postfix to infix expression for inorder traversal int main() { char postfix[] = "12+56*9*-"; ETree* r = constructTree(postfix); printf("Infix expression is "); inorder(r); return 0; }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions