cghun 2020. 12. 6. 21:08

const { object } = require("underscore");

 

class Stack {

constructor() {

this.storage = {};

this.top = -1;

}

 

size() {

return this.top+1;

}

 

push(element) {

 

this.storage[this.top +1] = element

this.top = this.top +1;

}

 

pop() {

let result = this.storage[this.top]

if(this.top === -1){

this.top = 0

}

else {

delete this.storage[this.top]

this.top = this.top - 1

}

return result

}

}



module.exports = Stack;