Skip to content
Eugene Lazutkin edited this page Jul 18, 2026 · 9 revisions

Queue adapter over any list.

Legend for tables
  • API

    • value - the value to be stored in the queue
    • values - an iterable that provides values
    • iterator - an Iterator instance or an object with an iterator/iterable protocol
  • Complexity

    • O - complexity of an operation
    • O(1) - constant time
    • O(n) - linear time proportional to the queue size
    • O(log n) - logarithmic time
    • O(k) - linear time proportional to the argument size

Queue adapter; defaults to ValueList:

import Queue from 'list-toolkit/queue.js';

const queue = new Queue();

Class Queue

Methods:

Member Return type Description O
constructor(underlyingList = new ValueList()) this constructs a new Queue O(k)
isEmpty boolean checks if the queue is empty O(1)
size number the queue's size O(1)
list list the underlying list O(1)
top value or undefined the queue's top element O(1)
front value or undefined an alias for top O(1)
peek() value or undefined the queue's top element O(1)
add(value) this add an element to the queue O(1)
push(value) this an alias for add(value) O(1)
pushBack(value) this an alias for add(value) O(1)
enqueue(value) this an alias for add(value) O(1)
remove() value or undefined remove and return the queue's top element O(1)
pop() value or undefined an alias for remove() O(1)
popFront() value or undefined an alias for remove() O(1)
dequeue() value or undefined an alias for remove() O(1)
addValues(values) this add an array of elements to the queue O(k)
pushValues(values) this an alias for addValues(values) O(k)
clear() this remove all elements from the queue O(1)
[Symbol.iterator]() iterator return the default iterator starting from the first element O(1)
getReverseIterator() iterator or undefined return the reverse iterator starting from the last element O(1)

Static members:

Member Return type Description O
from(values, underlyingList?) Queue create a queue from an iterable O(k)

Constructor accepts a list instance (DLL or SLL; adopted) or a list class (instantiated); a non-empty instance triggers O(n) size initialization.

top/peek() return front.value. For node-based lists, access the node directly via list.front.

add()/remove() delegate to pushBack()/popFront(). For SLL, getReverseIterator() returns undefined.

Alias families (zero-cost, not thunks): add/remove, push/pop, pushBack/popFront, enqueue/dequeue. Naming follows the toolkit-wide API conventions: a queue's push/pop are its FIFO pipe ends (in at the back, out at the front).

Exports

Queue is the default export.

Clone this wiki locally