-
-
Notifications
You must be signed in to change notification settings - Fork 0
Stack
Eugene Lazutkin edited this page Mar 10, 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();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) |
pop() |
value or undefined
|
remove and return the stack's top element | O(1) |
pushValues(values) |
this |
push values onto the stack sequentially | 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) |
Constructor takes a list class (not instance); a new instance is created internally.
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.
Stack is the default export.
Concepts
DLL: doubly linked lists
SLL: singly linked lists
Unrolled list
List utilities
Caches
Heaps
Queue, Stack, and Deque
Trees
Skip list
Timer wheel
Free list