Question: Develop c++ program to convert infix to postfix and evaluate the postfix expression: 1. Must use stack class with .h and.cpp seperate files 2.Priority =
Develop c++ program to convert infix to postfix and evaluate the postfix expression:
1. Must use stack class with .h and.cpp seperate files
2.Priority =
*, /
+, -
(
psudocode to implement:
Initialize an empty stack (for operators)
While not_finished parsing the expression
{obtain the next input token in the expression;
switch (token)
{case : break; //space
case (: push; break;
case ): pop & display popped element until ( is encountered;
//do not display the (
break;
case +, -, *, /, %: //( and ) are not considered as operators
if empty_stack or priority(token) > priority(stack_top)
push;
else
pop & display popped element until empty_stack or until
priority(token)<=priority(stack_top)
push
break;
case operand: display;
break;
} }
pop & display the rest of the stack elements; //do not display the (
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
