21. Use a stack to evaluate the following postfix expression and show the content of the stack after execution of each operation. Don’t write any code. Assume as if you are using push and pop member functions of the stack AB – CD + E * +

(where A = 5, B = 3, C = 5, D= 4, and E= 2)

 

Algo :
1) If operand is encountered, push it onto Stack
[End If]
2) If operator is encountered, Pop two elements
i) A -> Top element
ii) B-> Next to Top element
iii) Evaluate B operator A
push B operator A onto Stack
2) Set result = pop

Putting the values
Postfix : 5, 3, -, 5, 4, +, 2, *, +

stack
5

stack
3
5

stack
2

stack
5
2

stack
4
5
2

stack
9
2

stack
2
9
2

stack
18
2

stack
20

Output : 20