数组
let array = [1, 2, 3]
栈:
let stack = [1, 2, 3]
// 进栈
stack.push(4)
// 出栈
stcak.pop()
队列:
let queue = [1, 2, 3]
// 进队
queue.push(4)
// 出队
queue.shift()在 JavaScript 中, 数组的存储
class Stack {
constructor(...args){
this.stack = [...args]
}
//
push(...items){
return this.stack.push(...items)
}
pop(){
return this.stack.pop()
}
peek(){
return this.isEmpty() ? undefined : this.stack(this.size() -1)
}
isEmpty(){
return this.size() == 0
}
size(){
return this.stack.length
}
}
最后更新于