Skip to content

[FEATURE REQUEST] <Implementation of Stack using Queues> #4789

@IndranjanaChatterjee

Description

@IndranjanaChatterjee

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

  1. Initialization:

    • Create two empty queues, let's call them queue1 and queue2.
  2. 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.
  3. Pop Operation:

    • pop the topmost element from queue2.
  4. Top Operation:

    • Peek and return the last element from queue2.

Additional Information

I would like to add this Algorithm

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions