interface Node { next: undefined | Node data: Data } /** * Just a simple LinkedList */ export default class Stack { _head: undefined | Node constructor() { this._head = undefined } peek() { return this._head && this._head.data } pop() { const head = this._head if (!head) { return undefined } this._head = head.next return head.data } push(data: Data) { const node = {next: this._head, data} this._head = node } }