मराठी

Evaluate using stack 10, 3,*,30,2,*,-

Advertisements
Advertisements

प्रश्न

Evaluate using stack 10, 3,*,30,2,*,-

मूल्यांकन
Advertisements

उत्तर

Scan the expression from left to right and use a stack. Push 10 and 3; multiply them to get 30. Then push 30 and 2; multiply them to get 60. Finally, subtract the second popped value from the first popped value: 30 − 60 = −30. Therefore, the final answer is −30.

Operator/Operand Stack Calculation Meaning
10 10   Operand pushed to stack
3 10, 3   Operand pushed to stack
* 30 10 × 3 = 30 Pop last two operands, perform the operation and push the result onto stack
30 30, 30   Operand pushed to stack
2 30, 30, 2   Operand pushed to stack
* 30, 60 30 × 2 = 60 Pop last two operands, perform the operation and push the result onto stack
- -30 30 − 60 = -30 Pop last two operands, perform the operation and push the result onto stack
shaalaa.com
  या प्रश्नात किंवा उत्तरात काही त्रुटी आहे का?
पाठ 6: Stacks & Queues in list - EXERCISE [पृष्ठ १२३]

APPEARS IN

सीबीएसई Computer Science with Python [English] Class 12
पाठ 6 Stacks & Queues in list
EXERCISE | Q 9. | पृष्ठ १२३
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×