Evaluate the given postfix notation of expression :-
6, 5, 2, *, 10, 4, +, +, -
6, 5, 2, *, 10, 4, +, +, -
Symbol Scanned
|
Operation
|
Stack
|
6
|
Push to Stack
|
6
|
5
|
Push to Stack
|
6
5
|
2
|
Push to Stack
|
6
5 2
|
*
|
Pop 2
Pop 5
5 * 2 = 10
Push 10
|
6
5
6
6
10
|
10
|
Push to Stack
|
6
10 10
|
4
|
Push to Stack
|
6
10 10 4
|
+
|
Pop 4
Pop 10
10 + 4 = 14
Push 14
|
6
10 10
6
10
6
10 14
|
+
|
Pop 14
Pop 10
10 + 14 = 24
Push 24
|
6
10
6
6
24
|
-
|
Pop 24
Pop 6
6 – 24 = -18
Push -18
|
6
-18
|
Result : -18
No comments:
Post a Comment