UGC-NET Jan 2017 · Stacks

MCQ · 2 marks · Problem PROG-DSTR-0039

The seven elements $A, B, C, D, E,F$ and $G$ are pushed onto a stack in reverse order, i.e., starting from $G$. The stack is popped five times and each element is inserted into a queue. Two elements are deleted from the queue and pushed back onto the stack. Now, one element is popped from the stack. The popped item is .
  1. A
    $A$
  2. B
    $B$
  3. C
    $F$
  4. D
    $G$

Solve it on GATE DA practice →More Basic Data Structures problems

Show the worked solutionPushing G, F, E, D, C, B, A leaves A on top (stack bottom to top: G F E D C B A). Pop five times: A, B, C, D, E go into the queue in that order; the stack is now G F. Delete two from the queue: A then B (first in, first out). Push them: A, then B, so the stack is G F A B. Pop once: the top element is B.Answer: B

GATE DA practice: past exam problems by chapter, with worked solutions · gatedaprep.com