Typed API (TypeDoc) / Stack
Class: Stack<E>
Defined in: stack.ts:45
Type Parameters
E
E
Value type.
Implements
IStack<E>
Constructors
Constructor
new Stack<
E>(elements?):Stack<E>
Defined in: stack.ts:56
Parameters
elements?
Iterable<E, any, any>
Returns
Stack<E>
Properties
comparator
comparator:
Comparator<E>
Defined in: stack.ts:54
Comparator used for equality/sort checks.
Implementation of
size
size:
number=0
Defined in: stack.ts:50
Current element count.
Implementation of
Methods
[iterator]()
[iterator]():
Iterator<E>
Defined in: stack.ts:127
Returns
Iterator<E>
Implementation of
IStack.[iterator]
add()
add(
e):void
Defined in: stack.ts:145
Append an element.
Parameters
e
E
Returns
void
Remarks
Complexity: Amortized O(1) unless stated otherwise.
Implementation of
addAll()
addAll(
collection):void
Defined in: stack.ts:152
Append every element from another collection.
Parameters
collection
ICollection<E>
Returns
void
Remarks
Complexity: O(n + m) where m is collection.size.
Implementation of
clear()
clear():
void
Defined in: stack.ts:67
Remove all entries.
Returns
void
Remarks
Complexity: O(n)
Implementation of
contains()
contains(
element):boolean
Defined in: stack.ts:111
Test membership using the comparator when available.
Parameters
element
E
Returns
boolean
Remarks
Complexity: O(n) worst case
Implementation of
isEmpty()
isEmpty():
boolean
Defined in: stack.ts:75
Check for emptiness.
Returns
boolean
true when size === 0.
Implementation of
pop()
pop():
E
Defined in: stack.ts:91
Pop and return the top value.
Returns
E
Removed value.
Remarks
Complexity: O(1)
Implementation of
push()
push(
e):void
Defined in: stack.ts:101
Push a value on top.
Parameters
e
E
Value to push.
Returns
void
Remarks
Complexity: O(1)
Implementation of
remove()
remove(
target,isIndex):number|E
Defined in: stack.ts:161
Remove by value or index.
Parameters
target
Element or index.
number | E
isIndex
boolean = true
When true, treat e as index.
Returns
number | E
Removed element or index of removal.
Remarks
Complexity: O(n) worst case.
Implementation of
reverseIterator()
reverseIterator():
Generator<E>
Defined in: stack.ts:184
Iterates elements from the most recently added to the earliest.
Returns
Generator<E>
Implementation of
sort()
sort(
cmp?):void
Defined in: stack.ts:198
Sort the structure using the provided comparator.
Parameters
cmp?
Comparator<E>
Optional comparator; falls back to the internal one.
Returns
void
Implementation of
top()
top():
E
Defined in: stack.ts:82
Peek the top value without removing it.
Returns
E
Top value.