Options
All
  • Public
  • Public/Protected
  • All
Menu

The queue data structure allows you to perform FIFO operations in constant time. You can enqueue, dequeue and peek an item, and get the size of the queue. JavaScript arrays have 'shift' and 'push' methods but 'shift' take O(n) time.

Hierarchy

  • Queue

Index

Constructors

Properties

Methods

Constructors

constructor

Properties

Private end

end: number

Private front

front: number

Private store

store: Record<number, any>

Methods

dequeue

  • dequeue(): any | undefined
  • Removes an item from the queue and return its value. Time complexity: O(1).

    Returns any | undefined

    The value stored in item.

enqueue

  • enqueue(value: any): void
  • Adds an item to the end of the queue. Time complexity: O(1).

    Parameters

    • value: any

    Returns void

peek

  • peek(): any | undefined
  • Returns the item at front of the queue without dequeuing. Time complexity: O(1).

    Returns any | undefined

    The value stored in the item.

size

  • size(): number
  • Returns the current size of the queue. Time complexity: O(1).

    Returns number

    Size of the queue.

Legend

  • Constructor
  • Property
  • Method
  • Private property

Generated using TypeDoc