Data Structures & Algorithms
Unit -3
Postfix Expression Evaluation using Stack
Pankaj Chandra
Assistant Professor
IT GGV
Postfix Expression Evaluation using Stack
A postfix expression can be evaluated using the Stack data structure. To
evaluate a postfix expression using Stack data structure we can use the
following steps –
[Link] all the symbols one by one from left to right in the given Postfix Expression
[Link] the reading symbol is operand, then push it on to the Stack.
[Link] the reading symbol is operator (+ , - , * , / etc.,), then perform TWO pop
operations and store the two popped operands in two different variables (Value1
and Value2).
Value 1 = Top Element
Value 2 = Next to Top Element
Postfix Expression Evaluation using Stack
4. Then perform reading symbol operation using value1
and value2 and push result back on to the Stack.
Evaluate – Value 2 ↑ Value 1
Where ↑ is Operator
[Link]! perform a pop operation and display the
popped value as final result.
Postfix Expression Evaluation using Stack
Infix Expression – (5+3)*(8-2)
Postfix Expression – 5,3,+,8,2,-, *
Postfix Expression Evaluation using Stack
Infix Expression – (5+3)*(8-2)
Postfix Expression – 5,3,+,8,2,-, *
Postfix Expression Evaluation using Stack
Infix Expression – (5+3)*(8-2)
Postfix Expression – 5,3,+,8,2,-, *
Postfix Expression Evaluation using Stack
Infix Expression – (5+3)*(8-2)
Postfix Expression – 5,3,+,8,2,-, *
Postfix Expression Evaluation using Stack
Infix Expression – (5+3)*(8-2)
Postfix Expression – 5,3,+,8,2,-, *
Postfix Expression Evaluation using Stack
Infix Expression – (5+3)*(8-2)
Postfix Expression – 5,3,+,8,2,-, *
Postfix Expression Evaluation using Stack
Infix Expression – (5+3)*(8-2)
Postfix Expression – 5,3,+,8,2,-, *
Postfix Expression Evaluation using Stack
Infix Expression – (5+3)*(8-2)
Postfix Expression – 5,3,+,8,2,-, *
Postfix Expression Evaluation using Stack
Infix Expression – (5+3)*(8-2)
Postfix Expression – 5,3,+,8,2,-, *
Thank You