Question-42
Data Structure
Stack
Queue
Let S
be a stack and Q
be a queue supporting the following operations:
Stack operation:
Push(d)
: Insert elementd
in stackPop()
: Remove element from the stack and return the removed element
Queue Operation:
Enqueue(d)
: Insert elementd
in queuedequeue()
: Remove element from the queue and return the removed element
Suppose initially elements A, B, C, D, E, F and G are pushed onto stack S
in reverse order, i.e., starting from G.
The following sequence of operations is performed on stack S
and queue Q
:
Q.Enqueue(S.Pop())
Q.Enqueue(S.Pop())
Q.Enqueue(S.Pop())
Q.Enqueue(S.Pop())
Q.Enqueue(S.Pop())
S.Push(Q.Dequeue())
S.Push(Q.Dequeue())
Result = S.Pop()
What would be the value of Result
after completion of operations ?
Answer