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