Question: 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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!