type QNode = { value: T, next?: QNode } class Queue { public length: number; private head?: QNode; private tail?: QNode; constructor() { this.head = this.tail = undefined; this.length = 0; } enqueue(item: T): void { const node = { value: item } as QNode; this.length++; if (!this.tail) { this.tail = this.head = node return } this.tail.next = node; this.tail = node; } deque(): T | undefined { if (!this.head) { return undefined; } this.length--; const head = this.head; this.head = this.head.next; return head.value; } peek(): T | undefined { return this.head?.value } } test("test that queue works", () => { const q = new Queue; q.enqueue(12); console.log(q); expect(q.length).toEqual(1); q.enqueue(13); console.log(q); expect(q.length).toEqual(2); })