Skip to content
StackDecode
Stacks & queuesExplained

Stack Using Queues

After each push, rotate the queue so the newest item is at the front.

Time

O(n) push or pop

Extra space

O(n)

Use it for

Implementing LIFO with FIFO parts.

An animated walkthrough for this algorithm isn’t built yet. The summary above explains the idea; see the related animated algorithms below to practise the same technique.