module.exports = function Stack() {
// 初始化栈仓库
const arr = []
// 压栈
this.push = item => arr.push(item)
// 弹栈
this.pop = () => arr.pop()
// 返回栈顶元素
this.top = () => arr[arr.length - 1]
// 栈的大小
this.size = () => arr.length
// 栈是否为空
this.isEmpty = () => arr.length === 0
// 清空栈
this.clear = () => arr.splice(0, arr.length)
}
原文:https://www.cnblogs.com/guojbing/p/10990822.html