UNPKG

@andranik-arakelyan/js-utilities

Version:
44 lines (43 loc) 1.33 kB
/** * A generic Queue implementation with First-In-First-Out (FIFO) behavior. * @template T The type of elements stored in the queue. */ export declare class Queue<T> { private items; /** * Adds an item to the end of the queue. * @param item The item to add to the queue. * @returns The new length of the queue. */ enqueue(item: T): number; /** * Removes and returns the item at the front of the queue. * @returns The removed item, or undefined if the queue is empty. */ dequeue(): T | undefined; /** * Returns the item at the front of the queue without removing it. * @returns The front item, or undefined if the queue is empty. */ peek(): T | undefined; /** * Checks if the queue is empty. * @returns True if the queue has no items, false otherwise. */ isEmpty(): boolean; /** * Gets the number of items in the queue. * @returns The queue size. */ size(): number; /** * Removes all items from the queue. */ clear(): void; /** * Returns all items in the queue as an array (without modifying the queue). * The first element in the array is the front of the queue, the last is the back. * @returns An array containing all queue items. */ toArray(): T[]; }