const DoublyLinkedList = require('./DoublyLinkedList.js');
class Queue {
constructor() {
this.dll = new DoublyLinkedList();
}
isEmpty() {
return this.size() === 0;
}
getFront() {
return this.isEmpty() ? null : this.dll.getHead();
}
getTail() {
return this.isEmpty() ? null : this.dll.getTail();
}
size() {
return this.dll.size();
}
// Add an item to the queue (Time complexity: O(1))
enqueue(value) {
return this.dll.insertTail(value);
}
// Remove an item from the queue (Time complexity: O(1))
dequeue() {
return this.dll.removeHead();
}
}
const queue = new Queue();