UNPKG

@gabrielrufino/cube

Version:

Data structures made in Typescript

64 lines (63 loc) 2.3 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 __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 Stack = /** @class */ (function (_super) { __extends(Stack, _super); function Stack() { var inputs = []; for (var _i = 0; _i < arguments.length; _i++) { inputs[_i] = arguments[_i]; } return _super.call(this, inputs) || this; } Stack.prototype.push = function (element) { this._data.push(element); return element; }; Stack.prototype.pop = function () { var element = this._data.pop(); return element; }; Stack.prototype.peek = function () { var topPosition = this.data.length - 1; return this.data[topPosition]; }; Stack.prototype.clear = function () { this._data = []; }; Object.defineProperty(Stack.prototype, "isEmpty", { get: function () { return this.data.length === 0; }, enumerable: false, configurable: true }); Stack.prototype[Symbol.toPrimitive] = function (type) { var primitives = { default: true, number: this.size, string: "".concat(this.data.join(', '), " [Top]"), }; return primitives[type]; }; return Stack; }(DataStructure_1.default)); exports.default = Stack;