KnowledgeBoat Logo
|

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 / D *

Python Stack

1 Like

Answer

AB * C / D * = 35 * / 4 *

Scanning from left to right :

SymbolActionStackIntermediate
output
3Push3
5Push5 3
*Pop twice, Evaluate and Push back#Empty3 * 5 = 15
15
1Push1 15
/Pop twice, Evaluate and Push back#Empty15/1 = 15
15
4Push4 15
*Pop twice, Evaluate and Push back#Empty15 * 4 = 60
60

Hence, AB * C / D * = 35 * / 4 * = 60

Answered By

1 Like


Related Questions