Advertisement
Guest User

Untitled

a guest
Jan 20th, 2020
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.14 KB | None | 0 0
  1. function Numberqueue() {
  2. this.stack = [];
  3. }
  4.  
  5. Numberqueue.prototype.enqueue = function(item) {
  6. if (typeof item !== "number") throw Error("not a number");
  7. this.stack.push(item);
  8. console.log(item + " is added to the top of the stack");
  9. };
  10.  
  11. Numberqueue.prototype.dequeue = function() {
  12. if (this.stack.length == 0) throw Error("stack is empty");
  13. console.log(this.stack[this.stack.length - 1] + " is removed from the stack");
  14. this.stack.pop();
  15. };
  16.  
  17. let prototypeStack = new Numberqueue();
  18.  
  19. prototypeStack.enqueue(2);
  20. prototypeStack.dequeue();
  21.  
  22. function NumberqueueInclosed() {
  23. this.stack = [];
  24.  
  25. this.enqueueIC = function(item) {
  26. if (typeof item !== "number") throw Error("not a number");
  27. this.stack.push(item);
  28. console.log(item + " is added to the top of the IC stack");
  29. };
  30.  
  31. this.dequeueIC = function() {
  32. if (this.stack.length == 0) throw Error("IC stack is empty");
  33. console.log(
  34. this.stack[this.stack.length - 1] + " is removed from the IC stack"
  35. );
  36. this.stack.pop();
  37. };
  38. }
  39.  
  40. let inclosedStack = new NumberqueueInclosed();
  41.  
  42. inclosedStack.enqueueIC(2)
  43. inclosedStack.dequeueIC();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement