text: const { NotImplementedError } = require('../extensions/index.js');
  
  const { ListNode } = require('../extensions/list-node.js');
  
  /**
   * Implement the Queue with a given interface via linked list (use ListNode extension above).
   *
   * @example
   * const queue = new Queue();
   *
   * queue.enqueue(1); // adds the element to the queue
   * queue.enqueue(3); // adds the element to the queue
   * queue.dequeue(); // returns the top element from queue and deletes it, returns 1
   * queue.getUnderlyingList() // returns { value: 3, next: null }
   */
  module.exports = class Queue {
  
    HEAD = null;
    length = 0;
  
    getUnderlyingList() {
      return this.HEAD;
    }
  
    enqueue(value) {
      if (this.length == 0) {
        this.HEAD = new ListNode(value);
      } else {
        let current = this.HEAD;
        while(current.next) {
          current = current.next;
        }
        current.next = new ListNode(value);
      }
      this.length++;
    }
  
    dequeue() {
      let value = this.HEAD.value;
      let current = this.HEAD;
      this.HEAD = current.next;
      current = null;
      return value;
    }
  
  }