队列(基于数组)

Run Settings
LanguageJavaScript
Language Version
Run Command
class Queue { constructor() { this.list = [] } push(value) { this.list.push(value) } pop() { return this.list.shift() } peek() { return this.list[0] } isEmpty() { return this.list.length === 0 } clear() { this.list = [] } size() { return this.list.length } toString() { return this.list.join(",") } } // 测试代码 const queue = new Queue(); queue.push(1) queue.push(3) queue.push(5) queue.pop(); queue.push(7) console.log(queue.toString()) console.log(queue.peek()) console.log(queue.size()) console.log(queue.isEmpty()) queue.clear(); console.log(queue.toString()) console.log(queue.isEmpty())
Editor Settings
Theme
Key bindings
Full width
Lines