123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100 |
- module.exports = class Stack {
- constructor(stack) {
- this.pointer = 0;
- this._stack = stack;
- }
-
- Next() {
- this.pointer++;
- return this;
- }
-
- Prev() {
- this.pointer--;
- }
-
- GetAtIndex(index) {
- if (index == null || Number.isNaN(index) || !Number.isInteger(index)) {
- throw new TypeError("index must be an integer");
- }
- try {
- return index !== null ? this._stack[index] : this._stack[this.pointer];
- }
- catch (e) {
- return 0;
- }
- }
-
- GetUsingStackValue() {
- return this.Get(this._stack[this.pointer]);
- }
-
- Push(value) {
- this._stack[++this.pointer] = value;
- }
-
- Pop() {
- return this._stack.pop();
- }
-
- Put(index, value) {
- this._stack[index] = value;
- }
-
- Dump() {
- return this._stack;
- }
- };
|