{"size": 848, "ext": "js", "max_stars_repo_path": "code challenges/queueWithStacks/queue-with-stacks.js", "max_stars_repo_name": "KlNGU/data-structures-and-algorithms", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "code challenges/queueWithStacks/queue-with-stacks.js", "max_issues_repo_name": "KlNGU/data-structures-and-algorithms", "max_issues_repo_issues_event_min_datetime": "2020-09-04T19:10:29.000Z", "max_issues_repo_issues_event_max_datetime": "2021-05-07T11:08:42.000Z", "max_forks_repo_path": "code challenges/queueWithStacks/queue-with-stacks.js", "max_forks_repo_name": "KlNGU/data-structures-and-algorithms", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": 2, "max_forks_count": null, "avg_line_length": 15.7037037037, "max_line_length": 32, "alphanum_fraction": 0.554245283}
'use strict';

class Node {
  constructor (value) {
    this.value = value;
    this.next = null;
  }
}

class PseudoQueue {

  constructor() {
    this.first = null;
    this.last = null;
    this.size = 0;
  }

  enqueue(value) {
    let node = new Node(value);
    if(!this.first) {
      this.first = node;
      this.last = node;
    } else {
      node.next = this.first;
      this.first = node;
    }
    this.size++;
  }

  dequeue() {
    if(!this.first) { 
      return null;
    }
    let node = this.first
    if(!node.next) {
      node = node.next;
      this.first = node;
    } else {
      this.first = null;
      this.last = null;
    }
    this.size--;
  }
}

let myQueue = new PseudoQueue();
myQueue.enqueue(1);
myQueue.enqueue(2);
myQueue.enqueue(3);
myQueue.dequeue();

console.log(myQueue);
console.log(myQueue.dequeue());
