{
  "version": 3,
  "sources": ["../../src/queue/queue.ts"],
  "sourcesContent": ["/**\n * Represents a node in a singly linked list structure, used internally by the Queue.\n *\n * Example:\n *   const node = new Node<number>(42);\n *   console.log(node.data); // 42\n *   console.log(node.next); // null\n */\nexport class Node<T> {\n  data: T\n  next: Node<T> | null\n  constructor(data: T) {\n    this.data = data\n    this.next = null\n  }\n}\n\n/**\n * A generic queue implementation using a singly linked list.\n *\n * Example usage:\n *\n *   const q = new Queue<number>();\n *   q.enqueue(1);\n *   q.enqueue(2);\n *   q.enqueue(3);\n *   console.log(q.dequeue()); // 1\n *   console.log(q.peek());    // 2\n *   console.log(q.getSize()); // 2\n *   console.log(q.toString()); // \"2 -> 3\"\n *   console.log(q.isEmpty()); // false\n */\n\nexport class Queue<T> {\n  front: Node<T> | null\n  rear: Node<T> | null\n  size: number\n\n  constructor() {\n    this.front = null\n    this.rear = null\n    this.size = 0\n  }\n\n  /**\n   * Adds an element to the end of the queue.\n   * @param data - The data to add to the queue.\n   */\n  enqueue(data: T) {\n    const newNode = new Node(data)\n    if (this.isEmpty() || !this.rear) {\n      this.front = newNode\n      this.rear = newNode\n    } else {\n      this.rear.next = newNode\n      this.rear = newNode\n    }\n    this.size++\n  }\n\n  /**\n   * Removes and returns the front element of the queue.\n   * @returns The data from the removed node, or null if the queue is empty.\n   */\n  dequeue() {\n    if (this.isEmpty() || !this.front) {\n      return null\n    }\n    const removedNode = this.front\n    this.front = this.front.next\n    if (this.front === null) {\n      this.rear = null\n    }\n    this.size--\n    return removedNode.data\n  }\n\n  /**\n   * Returns the front element of the queue without removing it.\n   * @returns The front data, or null if the queue is empty.\n   */\n  peek() {\n    if (this.isEmpty() || !this.front) {\n      return null\n    }\n    return this.front.data\n  }\n\n  /**\n   * Checks whether the queue is empty.\n   * @returns True if the queue has no elements, false otherwise.\n   */\n  isEmpty() {\n    return this.size === 0\n  }\n\n  /**\n   * Returns the number of elements in the queue.\n   * @returns The size of the queue.\n   */\n  getSize() {\n    return this.size\n  }\n\n  /**\n   * Returns a string representation of the queue.\n   * @returns Elements of the queue separated by ' -> '.\n   */\n  toString() {\n    let current = this.front\n    const elements = []\n    while (current) {\n      elements.push(current.data)\n      current = current.next\n    }\n    return elements.join(' -> ')\n  }\n}\n"],
  "mappings": "AAQO,MAAM,KAAQ;AAAA,EACnB;AAAA,EACA;AAAA,EACA,YAAY,MAAS;AACnB,SAAK,OAAO;AACZ,SAAK,OAAO;AAAA,EACd;AACF;AAkBO,MAAM,MAAS;AAAA,EACpB;AAAA,EACA;AAAA,EACA;AAAA,EAEA,cAAc;AACZ,SAAK,QAAQ;AACb,SAAK,OAAO;AACZ,SAAK,OAAO;AAAA,EACd;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,QAAQ,MAAS;AACf,UAAM,UAAU,IAAI,KAAK,IAAI;AAC7B,QAAI,KAAK,QAAQ,KAAK,CAAC,KAAK,MAAM;AAChC,WAAK,QAAQ;AACb,WAAK,OAAO;AAAA,IACd,OAAO;AACL,WAAK,KAAK,OAAO;AACjB,WAAK,OAAO;AAAA,IACd;AACA,SAAK;AAAA,EACP;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,UAAU;AACR,QAAI,KAAK,QAAQ,KAAK,CAAC,KAAK,OAAO;AACjC,aAAO;AAAA,IACT;AACA,UAAM,cAAc,KAAK;AACzB,SAAK,QAAQ,KAAK,MAAM;AACxB,QAAI,KAAK,UAAU,MAAM;AACvB,WAAK,OAAO;AAAA,IACd;AACA,SAAK;AACL,WAAO,YAAY;AAAA,EACrB;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,OAAO;AACL,QAAI,KAAK,QAAQ,KAAK,CAAC,KAAK,OAAO;AACjC,aAAO;AAAA,IACT;AACA,WAAO,KAAK,MAAM;AAAA,EACpB;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,UAAU;AACR,WAAO,KAAK,SAAS;AAAA,EACvB;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,UAAU;AACR,WAAO,KAAK;AAAA,EACd;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,WAAW;AACT,QAAI,UAAU,KAAK;AACnB,UAAM,WAAW,CAAC;AAClB,WAAO,SAAS;AACd,eAAS,KAAK,QAAQ,IAAI;AAC1B,gBAAU,QAAQ;AAAA,IACpB;AACA,WAAO,SAAS,KAAK,MAAM;AAAA,EAC7B;AACF;",
  "names": []
}
