a zip code crypto-currency system good for red ONLY

Queue.js 681B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. "use strict";
  2. module.exports = class Queue {
  3. constructor(items) {
  4. this.first = null;
  5. this.last = null;
  6. this.length = 0;
  7. if(items) {
  8. for(const item of items) {
  9. this.enqueue(item);
  10. }
  11. }
  12. }
  13. enqueue(item) {
  14. const first = this.first;
  15. const node = {
  16. item,
  17. next: null
  18. };
  19. if(first === null) {
  20. this.last = node;
  21. } else {
  22. first.next = node;
  23. }
  24. this.first = node;
  25. this.length++;
  26. }
  27. dequeue() {
  28. const last = this.last;
  29. if(last === null)
  30. return undefined;
  31. const next = last.next;
  32. if(next === null) {
  33. this.first = null;
  34. }
  35. this.last = next;
  36. this.length--;
  37. return last.item;
  38. }
  39. };