Convert the follwoing expressio to postfix notation. Show the state of stack and expression after each step.
( ( 2 * ( 6 + 3 ) ) / ( 4 - 6 + 4 ) ) / 5
Note:
1)no code is required.
Convert the follwoing expressio to postfix notation.
( ( 2 * ( 6 + 3 ) ) / ( 4 - 6 + 4 ) ) / 5
First we are going to start with ( 2 * ( 6 + 3 ) )
Step 1. We first see the first number 2 out put 2
Step 2. The first operator *, push it to the stack.
Step 3 We see the number 6, out put 6
26
Step 4 We see operator +, since the top operator in the stack, *, has higher priority we pop (+)
Step 5 We number 3, out put 3
263+
Step 6 We see operator /, since, because * is on the left of it, we pop *, and push /
263+*
second part ( 4 - 6 + 4 )
Step 7 We see first number 4 out put 4
4
Step 8 The first operator -, push it to the stack
Step 9 We see the number 6, out put 6
46
Step 10 We see operator +, since, because - is on the left of it, we pop -, and push +
46-
Step 11. We see number 4 out put 4
46-4
Step 12 Because the expression is ended, we pop all the operators in the stack
263+*46-4+/5/
Transform infix to postfix ( ( 2 * ( 6 + 3 ) ) / ( 4 - 6 + 4 ) ) / 5 = 263+*46-4+/5/
Comments
Leave a comment