@evolplus/evo-utils
Version:
Simple utilities solution.
67 lines (66 loc) • 2.2 kB
TypeScript
/**
* Class representing a Double Ended Queue (Deque).
* Allows insertion and removal of elements from both ends of the queue.
*
* @template T The type of elements that the deque will store.
*/
export declare class Dequeue<T> {
private capacity;
private list;
private head;
private tail;
/**
* Creates an instance of the Deque class with a specified capacity.
* Initializes the deque with an empty list and sets head and tail pointers.
*
* @param {number} capacity - The initial capacity of the deque.
*/
constructor(capacity: number);
/**
* Checks if the deque is full.
*
* @returns {boolean} True if the deque has reached its capacity, otherwise false.
*/
isEmpty(): boolean;
/**
* Appends an element at the end of the deque.
*
* @param {T} item - The element to be appended.
* @returns {boolean} Returns true if successfully, otherwise (the deque is full) it will returns false.
*/
add(value: T): boolean;
/**
* Returns the element at the front of the deque without removing it.
*
* @returns {T | undefined} The element at the front of the deque, or undefined if the deque is empty.
*/
peekFirst(): T | undefined;
/**
* Returns the element at the end of the deque without removing it.
*
* @returns {T | undefined} The element at the front of the deque, or undefined if the deque is empty.
*/
peekLast(): T | undefined;
/**
* Removes and returns the element at the front of the deque.
*
* @returns {T | undefined} The element at the front of the deque, or undefined if the deque is empty.
*/
shift(): T | undefined;
/**
* Removes and returns the element at the end of the deque.
*
* @returns {T | undefined} The element at the end of the deque, or undefined if the deque is empty.
*/
pop(): T | undefined;
/**
* Returns the current number of elements in the deque.
*
* @returns {number} The number of elements currently stored in the deque.
*/
count(): number;
/**
* Remove all elements of the current deque.
*/
clear(): void;
}