337 views
1 1 vote

The five items, $\mathrm{A, B, C, D,}$ and $\mathrm{E,}$ are pushed in a stack, one after the other, starting from $\mathrm{A}$. The stack is popped four times and each element is inserted in a queue. Then 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 $\qquad$

  1. $\mathrm{A}$
     
  2. $\mathrm{B}$
     
  3. $\mathrm{C}$
     
  4. $\mathrm{D}$

2 Answers

0 0 votes
Option D

After inserting all the elements into stack the stack looks like  A B C D E  top of stack is E

Step 2: now popped 4 elements from the stack and inserted into queue each . E,D,C,B are popped and

Queue contains E,D,C,B front is E and rear is B

Step 3 : two elements are deleted from. Queue so E,D ARE deleted and pushed into stack

So now stack contains  A,E,D

NOW again one element from stack is popped out

And the popped element is D
0 0 votes

Basic Operations on Stack: 

    Push   - New element in inserted.

    Pop     - Last recently inserted element is retrieved. 

 

Basic Operations on Queue:

    Enqueue   - Inserting a new element.

    Dequeue   - Retrieving a new element, that was inserted the first.

 

Basic Principle behind 

Stack - LIFO

Queue- FIFO

 

After the above operations as per the question, the Stack would be 

---------------

       D

       E

       A

---------------

 

hence D- top of the stack, so when pop() operation is done on the stack, we get 'D'.

Answer:
Position:
Show:

Related questions

1 1 vote
1 1 answer
289
289 views
GO Classes asked Dec 24, 2025
289 views
If one uses the straight two-way merge sort algorithm to sort the following elements in ascending order: $20,47,15,8,9,4,40,30,12,17$, then the order of these elements af...
2 2 votes
1 1 answer
181
181 views
GO Classes asked Dec 24, 2025
181 views
Consider the following Python code: x = 10 def modify(): x = 20 def inner(): nonlocal x x += 5 inner() return x result = modify()What ...
1 1 vote
1 1 answer
226
226 views
GO Classes asked Dec 24, 2025
226 views
Consider the following Python function definition:def update_list(element, data_list=[]): data_list.append(element) return data_listNow, analyze the result of the...
2 2 votes
1 1 answer
262
262 views
GO Classes asked Dec 23, 2025
262 views
You need to perform $N$ insertions and then $N$ lookups. Consider two different implementations for storing data:Implementation $\mathbf{1:}$ Using a built-in Python $\ve...