39/

directory
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 24, 2026 License: BSD-3-Clause

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:

  • in: keeps track of input items. It gives a way to quickly push items to the queue.

  • out: a list of items to remove - the top item is the first one in the queue.

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

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL