Computer Science

Evaluate following postfix expression while showing status of stack after each operation given A = 3, B = 5, C = 1, D = 4.

AB + C *

Python Stack

4 Likes

Answer

AB + C * = 35 + 1 *

Scanning from left to right :

SymbolActionStackIntermediate
output
3Push3
5Push5 3
+Pop twice and Evaluate and Push back#Empty3 + 5 = 8
8
1Push1 8
*Pop twice, Evaluate Push back#Empty1 * 8 = 8
8

Hence, AB + C * = 35 + 1 * = 8

Answered By

1 Like


Related Questions