Implement LIFO (Last-In-First-Out) stacks and FIFO (First-In-First-Out) queues. Both are fundamental for parsing, undo/redo, and task scheduling.
class Stack {
constructor() { this.items = []; }
push(x) { this.items.push(x); }
pop() { return this.items.pop(); }
peek() { return this.items[this.items.length - 1]; }
}
// ...Implement LIFO (Last-In-First-Out) stacks and FIFO (First-In-First-Out) queues. Both are fundamental for parsing, undo/redo, and task scheduling.
class Stack {
constructor() { this.items = []; }
push(x) { this.items.push(x); }
pop() { return this.items.pop(); }
peek() { return this.items[this.items.length - 1]; }
}
// ...