UNPKG

@gabrielrufino/cube

Version:

Data structures made in Typescript

74 lines (73 loc) 2.76 kB
"use strict"; var __extends = (this && this.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { if (typeof b !== "function" && b !== null) throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) { if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) { if (ar || !(i in from)) { if (!ar) ar = Array.prototype.slice.call(from, 0, i); ar[i] = from[i]; } } return to.concat(ar || Array.prototype.slice.call(from)); }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); var DataStructure_1 = __importDefault(require("../DataStructure")); var Queue = /** @class */ (function (_super) { __extends(Queue, _super); function Queue() { var inputs = []; for (var _i = 0; _i < arguments.length; _i++) { inputs[_i] = arguments[_i]; } return _super.call(this, inputs) || this; } Object.defineProperty(Queue.prototype, "isEmpty", { get: function () { return this.size === 0; }, enumerable: false, configurable: true }); Queue.prototype.enqueue = function (element) { this._data = __spreadArray(__spreadArray([], this.data, true), [element], false); return element; }; Queue.prototype.dequeue = function () { var _a = this.data, element = _a[0], rest = _a.slice(1); this._data = rest; return element; }; Queue.prototype.peek = function () { var element = this.data[0]; return element; }; Queue.prototype.clear = function () { this._data = []; }; Queue.prototype[Symbol.toPrimitive] = function (type) { var primitives = { default: true, number: this.size, string: "[Front] ".concat(this.data.join(', ')), }; return primitives[type]; }; return Queue; }(DataStructure_1.default)); exports.default = Queue;