Evaluate the given postfix equation :-
20, 8, 4, /, 2, 3, +, *, -
20, 8, 4, /, 2, 3, +, *, -
Symbol Scanned
|
Operation
|
Stack
|
20
|
Push to Stack
|
20
|
8
|
Push to Stack
|
20
8
|
4
|
Push to Stack
|
20
8 4
|
/
|
Pop 4
Pop 8
8/4 = 2
Push 2
|
20
8
20
20
2
|
2
|
Push to Stack
|
20
2 2
|
3
|
Push to Stack
|
20
2 2 3
|
+
|
Pop 3
Pop 2
2 + 3 = 5
Push 5
|
20
2 2
20
2
20
2 5
|
*
|
Pop 5
Pop 2
2 * 5 = 10
Push 10
|
20
2
20
20
10
|
-
|
Pop 10
Pop 20
20 – 10 = 10
Push 10
|
20
10
|
Result
: 10
No comments:
Post a Comment