CENGAGE I MINDTAP Programming Exercise 17-10 CO I Instructions
<I>
Instructions
– infixToPostFixlmp…. I infixToPostfix.h I main.cpp myStack.h I stackADT.h
(Infix to Postfix) Write a program that converts an infix expression into an equivalent postfix expression. The rules to convert an infix expression into an equivalent postfix expression are as follows:
Suppose inf x represents the infix expression and pf x represents the postfix expression. The rules to convert inf x into pf x are as follows:
I. Initialize pf x to an empty expression and also initialize the stack.
2. Get the next symbol. sym . from infx . o If sym is an operand. append sym to pfx .
o If sym is (. push sym into the stack.
o If sym is ). pop and append all of the symbols from the stack until the most recent left parentheses. Pop and discard the left parentheses.
o If sym is an operator: ■ Pop and append all of the operators from the stack to pf x that are above the most recent left parentheses and have precedence greater than or equal to sym ■ Push sym onto the stack.
(0) 1/3 II
II
#include <iostream> 2 #include <string> 3 #include “myStack.h” 4 #include “infixToPostfix.h” 5 6 using namespace std; 7 8 int main() { 9 // Write your main here 10 11 return 0; 12 } 13
/ ■
Q Search this course
e x
>_ Terminal
sandbox $
Iry
• r S 0