tstruct
Version:
Data structures & basic algorithms library
40 lines (39 loc) • 1.16 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.Stack = void 0;
var LinkedList_1 = require("../LinkedList/LinkedList");
var Stack = (function () {
function Stack() {
this._list = new LinkedList_1.LinkedList();
}
Object.defineProperty(Stack.prototype, "isEmpty", {
get: function () {
return this._list.isEmpty;
},
enumerable: false,
configurable: true
});
Object.defineProperty(Stack.prototype, "size", {
get: function () {
return this._list.size;
},
enumerable: false,
configurable: true
});
Stack.prototype.push = function (val) {
this._list.add(val);
};
Stack.prototype.pop = function () {
if (this._list.size == 0)
return;
var val = this._list.tail.val;
var lastIndex = this._list.size - 1;
this._list.remove(lastIndex);
return val;
};
Stack.prototype[Symbol.iterator] = function () {
return this._list[Symbol.iterator]();
};
return Stack;
}());
exports.Stack = Stack;