in DS
10,443 views
5 votes
5 votes

The five items: A, B, C, D, and E are pushed in a stack, one after other starting from A. The stack is popped four items and each element is inserted in a queue. The two elements are deleted from the queue and pushed back on the stack. Now one item is popped from the stack. The popped item is

  1. A
  2. B
  3. C
  4. D
in DS
10.4k views

2 Comments

It should be D.
1
1
Surely D
0
0

2 Answers

19 votes
19 votes
Best answer

Initially A, B, C, D, and E are pushed in a stack, one after other starting from A.

Stack is popped four items.

Four element is inserted in a queue. The two elements are deleted from the queue

Two elements are pushed back on the stack.Now one item is popped from the stack. The popped item is D.

Correct option is D.

selected by
0 votes
0 votes
e

d

c

b

a

elements in the stack(pile of glasses, LIFO order, last element inserted will be the first to delete  ) initially

now 4 elements are popped out in order e d c b

now they are inserted into the queue so now the order of q is e d c b

in the queue, we delete from first element (FIFO  in reservation counter who comes first goes first)

now delete 2 elements  so e and d are deleted respectively

now insert the elements into stack in the order which they are deleted

so now stack is

d

e

a

now pop one element i.e is d
Answer:

Related questions