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