Thursday 28 May 2015

Q29,paper 2,J13. The value of postfix expression : 8 3 4 + – 3 8 2 / + * 2 $ 3 + is



(A) 17
(B) 131
(C) 64
(D) 52
Answer. D.                                           
Explanation.
Push 8,3,4 in a stack  (834*), 4 is the top.
Read op + , pop top element, calculate  3+4 and push in stack. Stack is (8,7*).
Read op - , pop top elements. Calculate 8-7 and push in stack. Stack is(1*)
Read 3,8,2 and push(3) push 8 and push 2. Stack is (1,3,8,2*)
Read /. Pop two elements operate them and push in stack.Stack is (1,3,4*).
Read +. Pop two elements operate them and push in stack.Stack is (1,7*).
Read *. Pop two elements operate them and push in stack.Stack is (7*).
Push 2.Stack is (7,2*).
Read $, Pop two elements operate them and push in stack.Stack is (49*).
Push 3 . stack is(49,3).
Read + Pop two elements operate them and push in stack.Stack is 52).

No comments:

Post a Comment

Note: only a member of this blog may post a comment.