Queue.uts 533 Bytes
export default class Queue<T> {
  items: T[]

  constructor(items: T[] = []) {
    this.items = items
  }

  enqueue(element: T) {
    this.items.push(element)
  }

  dequeue(): T | null {
    if (this.isEmpty()) {
      return null
    }
    return this.items.shift()
  }

  front(): T | null {
    if (this.isEmpty()) {
      return null
    }
    return this.items[0]
  }

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

  get size(): number {
    return this.items.length
  }

  clear() {
    this.items = []
  }
}