UNPKG

typescript-algorithms-and-datastructures

Version:
38 lines 1.22 kB
(function (factory) { if (typeof module === "object" && typeof module.exports === "object") { var v = factory(require, exports); if (v !== undefined) module.exports = v; } else if (typeof define === "function" && define.amd) { define(["require", "exports"], factory); } })(function (require, exports) { "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); class Queue { constructor(MAX_QUEUE_SIZE) { this.queue = []; this.head = 0; this.MAX_QUEUE_SIZE = 1000; this.MAX_QUEUE_SIZE = MAX_QUEUE_SIZE; } enqueue(element) { this.queue.push(element); } dequeue() { const output = this.queue[this.head]; this.queue[this.head] = null; this.head++; if (this.head >= this.MAX_QUEUE_SIZE) { this.queue.splice(0, this.head); this.head = 0; } return output; } size() { return this.queue.length - this.head; } } exports.Queue = Queue; }); //# sourceMappingURL=Queue.js.map