R
C

Stack

v0.0.2tested

Represents a stack data structure

Signature

ts
class Stack<T> implements StackLike<T>

Type Parameters

T

Properties

PropertyTypeDescription
lengthreadonlynumberGets the number of elements in the stack
isEmptyreadonlybooleanChecks if the stack is empty
isFullreadonlybooleanChecks if the stack is full

Methods

push

Pushes an element onto the stack

ts
public push(element: T)
ParameterTypeDescription
elementTThe element to push onto the stack
Returnsthis
pop

Pops an element from the stack

ts
public pop()
ReturnsT | undefinedThe element popped from the stack
peek

Peeks at the top element of the stack

ts
public peek()
ReturnsTThe top element of the stack
clear

Clears the stack

ts
public clear()
Returnsthis
toArray

Converts the stack to an array

ts
public toArray()
ReturnsT[]
toString

Returns a string representation of the stack

ts
public toString()
Returnsstring
[Symbol.iterator]

Returns an iterator for the stack

ts
public* [Symbol.iterator]()
ReturnsGenerator<NonNullable<T>, void, unknown>
[Symbol.asyncIterator]

Returns an async iterator for the stack

ts
public async* [Symbol.asyncIterator]()
ReturnsAsyncGenerator<Awaited<NonNullable<T>>, void, unknown>