@andranik-arakelyan/js-utilities
Version:
Javascript utilities
44 lines (43 loc) • 1.32 kB
TypeScript
/**
* A generic Stack implementation with Last-In-First-Out (LIFO) behavior.
* @template T The type of elements stored in the stack.
*/
export declare class Stack<T> {
private items;
/**
* Adds an item to the top of the stack.
* @param item The item to push onto the stack.
* @returns The new length of the stack.
*/
push(item: T): number;
/**
* Removes and returns the item at the top of the stack.
* @returns The removed item, or undefined if the stack is empty.
*/
pop(): T | undefined;
/**
* Returns the item at the top of the stack without removing it.
* @returns The top item, or undefined if the stack is empty.
*/
peek(): T | undefined;
/**
* Checks if the stack is empty.
* @returns True if the stack has no items, false otherwise.
*/
isEmpty(): boolean;
/**
* Gets the number of items in the stack.
* @returns The stack size.
*/
size(): number;
/**
* Removes all items from the stack.
*/
clear(): void;
/**
* Returns all items in the stack as an array (without modifying the stack).
* The first element in the array is the bottom of the stack, the last is the top.
* @returns An array containing all stack items.
*/
toArray(): T[];
}