3.3.7 f - Converting between reverse Polish notation and infix notation
Converting between reverse polish and infix notations
We have already said that a stack is a LIFO device and we know that stacks are used to evaluate expressions. We can diagrams of the stack to help us convert between reverse Polish notation and infix notation.
Example 1
Consider the algebraic expression: 4(A + B)
This uses the infix notation. Converting it to reverse Polish notation gives 4AB+*
How can I check this is correct? I fill the stack with operands, as I see them. So 4 goes in first, followed by A, followed by B. I then get to the first operand. The rule is as follows:
- Remove the two top items from the stack
- Do the expression given by the operand
- Return the result to the stack.
Read full article from Converting Polish and infix
No comments:
Post a Comment