dastal
Version:
Data Structures & Algorithms implementations
44 lines • 1.09 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.LinkedQueue = void 0;
const list_1 = require("../list");
/**
* A linked list implementation of the {@link Queue} interface
*/
class LinkedQueue {
/**
* Instantiate the queue.
*
* @param elements - A set of elements to initialize the queue with.
*/
constructor(elements) {
this.list = new list_1.LinkedList(elements);
}
clear() {
this.list.clear();
}
dequeue() {
return this.list.shift();
}
enqueue(element) {
return this.list.push(element);
}
peek() {
return this.list.get(0);
}
get size() {
return this.list.size;
}
/**
* Receive an iterator through the queue.
*
* **Note:** Unexpected behavior can occur if the collection is modified during iteration.
*
* @returns An iterator through the queue
*/
[Symbol.iterator]() {
return this.list[Symbol.iterator]();
}
}
exports.LinkedQueue = LinkedQueue;
//# sourceMappingURL=linkedQueue.js.map