Advertisement
Guest User

Untitled

a guest
Jul 18th, 2019
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.81 KB | None | 0 0
  1. function Queue() {
  2. this.collection = [];
  3.  
  4. // print the queue collection
  5. this.print = function () {
  6. return this.collection;
  7. };
  8.  
  9. this.enqueue = function (element) {
  10. this.collection.push(element);
  11. };
  12.  
  13. this.dequeue = function () {
  14. this.collection.shift();
  15. };
  16.  
  17. this.front = function () {
  18. return this.collection[0];
  19. };
  20.  
  21. this.size = function () {
  22. return this.collection.length;
  23. };
  24.  
  25. this.isEmpty = function () {
  26. return this.collection.length === 0;
  27. };
  28. };
  29.  
  30. const myQueue = new Queue();
  31. myQueue.enqueue(10);
  32. myQueue.enqueue(20);
  33. myQueue.enqueue(30);
  34.  
  35. console.log(myQueue.print());
  36. console.log(myQueue.front());
  37. myQueue.dequeue();
  38. console.log(myQueue.print());
  39. console.log(myQueue.size());
  40. console.log(myQueue.isEmpty());
  41. myQueue.dequeue();
  42. myQueue.dequeue();
  43. console.log(myQueue.isEmpty());
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement