Your approach is a refinement of our previous approach in that we will now store operators (and opening parentheses) in an OpStack stack. Working from left to right through the expression, process each "token":
Question: Now let's try something more challenging, convert the infix expression
7 * ( 2 + 4 ) + ( 5 * 4 - 2 * 3 ) / 2
into the equivalent postfix notation. You can fill in the table below with your work:
Token | Postfix Built | OpStack | Notes |
---|---|---|---|
7 | |||
* | |||
( | |||
2 | |||
+ | |||
4 | |||
) | |||
+ | |||
( | |||
5 | |||
* | |||
4 | |||
- | |||
2 | |||
* | |||
3 | |||
) | |||
/ | |||
2 | |||
(end) |