Stack and Queue with JavaScript

Run Settings
LanguageJavaScript
Language Version
Run Command
class Stack { constructor() { this.items = []; } pop() { return this.items.pop(); } push(data) { this.items.push(data); } getTop() { return this.items.length > 0 ? this.items[this.items.length - 1] : ''; } isEmpty() { return this.items.length == 0; } } class Queue { constructor() { this.items = []; } // 入队 enQueue(data) { this.items.push(data); } // 出队 deQueue() { this.items.shift(); } isEmpty() { return this.items.length == 0; } } let stack = new Stack(); stack.push(1); stack.push(2); stack.push(3); stack.push(4); stack.pop(); stack.push(5); console.log('stack',stack.items); let queue = new Queue(); queue.enQueue(1); queue.enQueue(2); queue.enQueue(3); queue.enQueue(4); queue.deQueue(); queue.enQueue(5); console.log('queue',queue.items);
Editor Settings
Theme
Key bindings
Full width
Lines