100% found this document useful (1 vote)
40 views13 pages

6 - Postfix Expression Evaluation Using Stack Data Structure

Uploaded by

Boyina Viswanth
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
40 views13 pages

6 - Postfix Expression Evaluation Using Stack Data Structure

Uploaded by

Boyina Viswanth
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 13

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 –

1.Read all the symbols one by one from left to right in the given Postfix Expression

2.If the reading symbol is operand, then push it on to the Stack.

3.If 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

5.Finally! 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

You might also like