@d1g1tal/collections
Version:
JavaScript Collections ES Modules
38 lines (36 loc) • 988 B
TypeScript
/** JavaScript implementation of a Stack */
declare class Stack<E> {
private readonly items;
/**
* Creates a new stack.
*/
constructor();
/**
* Pushes a value onto the stack.
* @param value - The value to be pushed.
*/
push(value: E): void;
/**
* Pops the top value off the stack and returns it.
* Returns undefined if the stack is empty.
* @returns The popped value or undefined.
*/
pop(): E | undefined;
/**
* Peeks at the top value on the stack without popping it.
* Returns undefined if the stack is empty.
* @returns The top value of the stack or undefined.
*/
peek(): E | undefined;
/**
* Checks if the stack is empty.
* @returns True if the stack is empty, false otherwise.
*/
isEmpty(): boolean;
/**
* Returns the number of items in the stack.
* @returns The number of items in the stack.
*/
get size(): number;
}
export { Stack };