C
Stack
v0.0.2testedRepresents a stack data structure
Signature
ts
class Stack<T> implements StackLike<T>Type Parameters
TProperties
| Property | Type | Description |
|---|---|---|
lengthreadonly | number | Gets the number of elements in the stack |
isEmptyreadonly | boolean | Checks if the stack is empty |
isFullreadonly | boolean | Checks if the stack is full |
Methods
pushPushes an element onto the stack
ts
public push(element: T)| Parameter | Type | Description |
|---|---|---|
element | T | The element to push onto the stack |
Returns
thispopPops an element from the stack
ts
public pop()Returns
T | undefinedThe element popped from the stackpeekPeeks at the top element of the stack
ts
public peek()Returns
TThe top element of the stackclearClears the stack
ts
public clear()Returns
thistoArrayConverts the stack to an array
ts
public toArray()Returns
T[]toStringReturns a string representation of the stack
ts
public toString()Returns
string[Symbol.iterator]Returns an iterator for the stack
ts
public* [Symbol.iterator]()Returns
Generator<NonNullable<T>, void, unknown>[Symbol.asyncIterator]Returns an async iterator for the stack
ts
public async* [Symbol.asyncIterator]()Returns
AsyncGenerator<Awaited<NonNullable<T>>, void, unknown>