directory
Version:
v0.1.0
Opens a new window with list of versions in this module.
Published: Sep 24, 2026
License: BSD-3-Clause
Opens a new window with license information.
README
¶
Name
39 - queue using stack
Description
Problem
Implement a queue using stack with the following API, derived from std::queue:
type Queue interface {
Empty() bool
Front() (int, bool)
Pop()
Push(int)
Size() int
}
Example
Solution
DetailsUse two stacks:
Performance:
-
time:
- Empty is O(1)
- Front is O(n) due to move from in to out stacks
- Pop is O(n) due to move from in to out stacks
- Push is O(1)
- Size is O(1)
-
space: O(n)
Directories
¶
Click to show internal directories.
Click to hide internal directories.