Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Queue<T>

Queue implementation based on a linked list. It has two methods enqueue and dequeue to manage its elements. It implements the CappedStructure interface to handle overflow of a capacity is set.

Type parameters

  • T

Hierarchy

  • Queue

Implements

Index

Constructors

Properties

Methods

Constructors

constructor

  • new Queue(capacity?: undefined | number): Queue
  • Constructor takes an optional capacity parameter. If set, the Queue won't accept new elements when the lengths reaches the capacity, until it is dequeued.

    Parameters

    • Optional capacity: undefined | number

      The maximum queue length before overflow.

    Returns Queue

Properties

Private Optional _first

_first: QueueNode<T>

Private Optional _last

_last: QueueNode<T>

capacity

capacity: number = -1

The maximum elements the structure can contain. It can be set via the constructor or setCapacity. Default value is -1 (no limit).

length

length: number = 0

The current amount of elements.

Methods

dequeue

  • dequeue(): T | undefined
  • Removes the first element of the list.

    Returns T | undefined

    The value of the element removed.

enqueue

  • enqueue(value: T): number
  • Adds an element to the end of the list and returns its length. If the length already reached the (optional) capacity, enqueue won't perform and return -1.

    Parameters

    • value: T

      The value associed to the element.

    Returns number

    The length of the current Queue after insertion, or -1 if it failed.

first

  • Returns the first element.

    Returns undefined | QueueNode<T>

last

  • Returns the last element.

    Returns undefined | QueueNode<T>

Generated using TypeDoc