What would you like to Propose?
Hello,
I would like to add the algorithm of implementation of Stack using Queues in java.
Issue details
Stack using Queues Algorithm
-
Initialization:
- Create two empty queues, let's call them
queue1 and queue2.
-
Push Operation:
- To push an element into the stack, enqueue the element to
queue1.
- Now pop all the elements from
queue2 until it becomes empty.
- Swap the two queues.
- For the next push operation
queue1 becomes queue2 and vice versa.
-
Pop Operation:
- pop the topmost element from
queue2.
-
Top Operation:
- Peek and return the last element from
queue2.
Additional Information
I would like to add this Algorithm