Concept Flow - Queue Using Two Stacks
Enqueue Operation
Push element onto Stack1
Done
Dequeue Operation
Is Stack2 empty?
NoβPop from Stack2
Yes
Transfer all elements from Stack1 to Stack2
Pop from Stack2
Done
Enqueue pushes elements onto the first stack. Dequeue pops from the second stack; if empty, elements are moved from the first stack to the second to reverse order.
