969 views
3 votes
3 votes

I am getting a) as ans. Plz tell how C?

2 Answers

0 votes
0 votes

Correct answer is C

Take an example. Queue Q contains 5 elements 10, 20, 30, 40 ,50.

Stack : __ __ __ __ __

Queue : 10 20 30 40 50

When queue is not empty, we are to perform PUSH operation 5 times taking all the 5 elements via dequeue operation.

So we push in sequence, 10, 20, 30 ,40, 50 (Since Queue is FIFO order) ie. elements will be removed in same sequence as they were inserted.

Stack : 10 20 30 40 50

Queue : __ __ __ __ __

Now again we Enqueue the elements one by one taking all the 5 elements via POP operation.

So enqueue in sequence 50 40 30 20 10. Here's the catch. POP removes elements from last. Since stack is LIFO order.

Stack : __ __ __ __ __

Queue : 50 40 30 20 10.

Hence, the contents of Queue is reversed the original content.  So, C is correct answer.

Related questions

0 votes
0 votes
1 answer
1
Abhrajyoti00 asked Oct 29, 2022
718 views
Can there be “Stack Overflow” in Linked list Implementation of stack? If Yes, how?