/**
* Simple Queue Implementation (for temporary use)
*/
class Queue {
constructor() {
this.items = []; // Use an array to store queue elements
}
/**
* Enqueues an element to the end of the queue.
* @param {any} element - The element to enqueue.
*/
enqueue(element) {
this.items.push(element);
}
/**
* Dequeues and returns the element at the front of the queue.
* Returns undefined if the queue is empty.
* @returns {any} The dequeued element.
*/
dequeue() {
if (this.isEmpty()) {
return undefined;
}
return this.items.shift(); // Remove and return the first element
}
/**
* Returns the element at the front of the queue without removing it.
* Returns undefined if the queue is empty.
* @returns {any} The element at the front.
*/
peek() {
if (this.isEmpty()) {
return undefined;
}
return this.items[0];
}
/**
* Checks if the queue is empty.
* @returns {boolean} True if the queue is empty, false otherwise.
*/
isEmpty() {
return this.items.length === 0;
}
/**
* Returns the number of elements in the queue.
* @returns {number} The queue's size.
*/
size() {
return this.items.length;
}
}
// Export the Queue class (for use in other modules)
export default Queue;
Add your comment