Advertisements
Advertisements
प्रश्न
Evaluate following postfix expressions while showing status of stack after the operation given A = 3, B = 5, C = 1, D = 4.
A B * C / D *
थोडक्यात उत्तर
Advertisements
उत्तर
A B * C / D *
A = 3, B = 5, C = 1, D = 4
Replacing Literals with Values:
Expression : A B * C / D *
After Substitution Expression: 3 5 * 1 / 4 *
Scanning from left to right
| Symbol | Action | Intermediate Process/Output | Stack, Initially Stack is Empty [ ] |
| 3 | PUSH(3) | 3 | |
| 5 | PUSH(5) | 3 5 | |
| * | POP twice, Evaluate and PUSH Back | POP( ) => 5 POP( ) => 3 3 * 5 = 15 PUSH(15) |
3 [ ] #Empty 15 |
| 1 | PUSH(1) | 15 1 | |
| / | POP twice, Evaluate and PUSH Back | POP( ) => 1 POP( ) => 15 15 / 1 = 15 PUSH(15) |
15 [ ] #Empty 15 |
| 4 | PUSH(4) | 15 4 | |
| * | POP twice, Evaluate and PUSH Back | POP( ) => 4 POP( ) => 15 15 * 4 = 60 PUSH(60) |
15 [ ] 60 |
| End of Expression | POP | POP( ) => 60 | [ ] |
| Answer : 60 |
shaalaa.com
Notations for Arithmetic Expressions
या प्रश्नात किंवा उत्तरात काही त्रुटी आहे का?
