Guest User

Untitled

a guest
Nov 22nd, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.68 KB | None | 0 0
  1. function Queue(){
  2. var items = [];
  3. var p = "";
  4. this.enqueue = function(element){
  5. items.push(element);
  6. }
  7. this.dequeue = function(){
  8. items.shift();
  9. }
  10. this.front = function(){
  11. if(items.length === 0){
  12. return 'Null Array';
  13. }else{
  14. return items[0];
  15. }
  16. }
  17.  
  18. this.isEmpty = function(){
  19. if(items.length === 0){
  20. return false;
  21. }else{
  22. return true;
  23. }
  24. }
  25.  
  26. this.size = function(){
  27. return items.length;
  28. }
  29. this.print = function(){
  30. for (var i = 0;i < items.length;i++){
  31. p += items[i];
  32. }
  33. return p;
  34. }
  35. }
  36.  
  37. var q = new Queue();
  38.  
  39. q.enqueue(1);
  40. q.enqueue(2);
  41. q.enqueue(3);
  42. console.log(q.print());
  43. q.dequeue();
  44. console.log(q.print());
Add Comment
Please, Sign In to add comment