File size: 488 Bytes
3459571
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
export class Stack<T> {
  private array: T[] = []

  pop(): T | undefined {
    if (this.isEmpty()) throw new Error()

    return this.array.pop()
  }

  push(data: T): void {
    this.array.push(data)
  }

  peek(): T {
    if (this.isEmpty()) throw new Error()

    return this.array[this.array.length - 1]
  }

  isEmpty(): boolean {
    return this.array.length === 0
  }

  size(): number {
    return this.array.length
  }

  reverseOutput(): T[] {
    return [...this.array]
  }
}