1class Stack {
2 constructor(maxSize = 10) {
3 this.items = [];
4 this.maxSize = maxSize;
5 }
6
7 push(value) {
8 if (this.items.length >= this.maxSize) {
9 throw new Error("Stack overflow");
10 }
11 this.items.push(value);
12 }
13
14 pop() {
15 if (this.items.length === 0) {
16 throw new Error("Stack underflow");
17 }
18 return this.items.pop();
19 }
20
21 peek() {
22 return this.items[this.items.length - 1];
23 }
24}