FOR ENQUEUE: 3 OPERATIONS (REVERSE,PUSH ,REVERSE)
Suppose the Order of queue operations is,
Enqueue(3,4,5),Dequeue(),Enqueue(6)
ENQUEUE USING STACK:
Then from 2nd Enqueue : Do reverse,PUSH,reverse
- Reverse→ Stack will be as it is
- Push
-
Reverse
So this is how a Single Enqueue operation would be.
Continue same for all enqueues till Enqueue(5)
Now for DEQUEUE: 1 OPERATION POP
As FIFO order should be followed Our Queue Automatically follows it by Enqueue operation.
So for Dequeue Simply do POP only and 3 will be popped off.
Continue Popping for all Dequeues
SO FOR ENQUEUE 3 OPERATIONS(REVERSE,PUSH,REVERSE) AND FOR DEQUEUE 1 OPERATION(POP)