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

Stack adapter over any list.

Legend for tables
  • API

    • value - the value to be stored in the stack
    • 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 stack size
    • O(k) - linear time proportional to the argument size

Stack adapter; defaults to ValueList:

import Stack from 'list-toolkit/stack.js';

const stack = new Stack();

Class Stack

Methods:

Member Return type Description O
constructor(underlyingList = ValueList) this constructs a new Stack O(1)
isEmpty boolean checks if the stack is empty O(1)
size number the stack's size O(1)
list list the underlying list O(1)
top value or undefined the stack's top element O(1)
peek() value or undefined the stack's top element O(1)
push(value) this push an element onto the stack O(1)
pushFront(value) this an alias for push(value) O(1)
add(value) this an alias for push(value) O(1)
pop() value or undefined remove and return the stack's top element O(1)
remove() value or undefined an alias for pop() O(1)
pushValues(values) this push values onto the stack sequentially O(k)
addValues(values) this an alias for pushValues(values) O(k)
clear() this remove all elements from the stack O(1)
[Symbol.iterator]() iterator return the default iterator starting from the top element O(1)
getReverseIterator() iterator or undefined return the reverse iterator starting from the bottom element O(1)

Static members:

Member Return type Description O
from(values, underlyingList?) Stack create a stack from an iterable (last value ends on top) O(k)

Notes on properties and methods

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

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

push()/pop() delegate to pushFront()/popFront(). For SLL, getReverseIterator() returns undefined.

Naming follows the toolkit-wide API conventions.

Exports

Stack is the default export.

Clone this wiki locally