// 栈构造函数
class Stack {
constructor() {
this.items = [];
}
push(item) {
this.items.push(item);
}
pop() {
return this.items.pop();
}
peek() {
return this.items[this.items.length - 1];
}
isEmpty() {
return this.items.length < 1;
}
clear() {
this.items = [];
}
size() {
return this.items.length;
}
print() {
console.log(this.items.toString())
}
}
// 实例化一个栈
let stack = new Stack();
Last Update: 2019-12-06 12:57:22 Source File