es-next-tools
Version:
A comprehensive utility library for JavaScript and TypeScript that provides a wide range of functions for common programming tasks, including mathematical operations, date manipulations, array and object handling, string utilities, and more.
47 lines (46 loc) • 1.45 kB
TypeScript
/**
* Represents a stack data structure.
* @template T The type of elements in the stack.
* @example
* const stack = new Stack<number>();
* stack.push(1).push(2);
* console.log(stack.pop()); // 2
*/
export declare class Stack<T> {
private items;
private itemSet;
/**
* Pushes an item onto the top of the stack.
* @param {T} item - The item to push onto the stack.
* @returns {T} The item that was pushed.
*/
push(item: T): T;
/**
* Removes and returns the item at the top of the stack.
* @returns {T} The item at the top of the stack, or undefined if the stack is empty.
* @throws {Error} If the stack is empty;
*/
pop(): T;
/**
* Returns the number of items in the stack.
* @returns {number} The size of the stack.
*/
size(): number;
/**
* Returns the item at the top of the stack without removing it.
* @returns {T | undefined} The item at the top of the stack, or undefined if the stack is empty.
*/
peek(): T | undefined;
select(item: number): T;
/**
* Checks if the stack is empty.
* @returns {boolean} True if the stack is empty, false otherwise.
*/
isEmpty(): boolean;
/**
* Checks if the stack contains a specific item.
* @param {T} item - The item to check for.
* @returns {boolean} True if the item is in the stack, false otherwise.
*/
contains(item: T): boolean;
}