// push methods
function append(e) {
this.stackList.push(e)
}
// pop methods
function pop() {
this.stackList.pop()
}
// peek methods
function peek() {
return this.stackList[this.size() - 1]
}
// isEmpty methods
function isEmpty() {
return !this.stackList.length
}
// clear methods
function clear() {
this.stackList = []
}
// size methods
function size() {
return this.stackList.length;
}
// Stack structure
function Stack() {
this.stackList = [];
this.append = append;
this.pop = pop;
this.peek = peek;
this.isEmpty = isEmpty;
this.clear = clear;
this.size = size;
}
let stack = new Stack()
stack.append('1')
stack.append('2')
stack.append('2')
console.log(stack.size())
console.log(stack.peek())
console