//创建栈
function Stack() {
let items = [];
//向栈中添加元素
this.push = function(element){
items.push(element);
}
//从栈中移除元素
this.pop = function(){
return items.pop();
}
//查看栈顶元素
this.peek = function() {
return items[items.length - 1];
}
//检查栈是否为空
this.isEmpty = function() {
return items.length == 0;
}
//返回栈的长度
this.size = function() {
return items.length;
}
//清空栈元素
this.clear = function() {
items = [];
}
//打印栈元素
this.print = function() {
console.log(items.toString());
}
}