Queue.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. var __extends = this && this.t || function() {
  2. var extendStatics = function(e, t) {
  3. extendStatics = Object.setPrototypeOf || {
  4. __proto__: []
  5. } instanceof Array && function(e, t) {
  6. e.__proto__ = t;
  7. } || function(e, t) {
  8. for (var n in t) if (Object.prototype.hasOwnProperty.call(t, n)) e[n] = t[n];
  9. };
  10. return extendStatics(e, t);
  11. };
  12. return function(e, t) {
  13. if (typeof t !== "function" && t !== null) throw new TypeError("Class extends value " + String(t) + " is not a constructor or null");
  14. extendStatics(e, t);
  15. function __() {
  16. this.constructor = e;
  17. }
  18. e.prototype = t === null ? Object.create(t) : (__.prototype = t.prototype, new __);
  19. };
  20. }();
  21. import Deque from "../SequentialContainer/Deque";
  22. import { Base } from "../ContainerBase";
  23. var Queue = function(e) {
  24. __extends(Queue, e);
  25. function Queue(t) {
  26. if (t === void 0) {
  27. t = [];
  28. }
  29. var n = e.call(this) || this;
  30. n.q = new Deque(t);
  31. n.o = n.q.size();
  32. return n;
  33. }
  34. Queue.prototype.clear = function() {
  35. this.q.clear();
  36. this.o = 0;
  37. };
  38. Queue.prototype.push = function(e) {
  39. this.q.pushBack(e);
  40. this.o += 1;
  41. };
  42. Queue.prototype.pop = function() {
  43. this.q.popFront();
  44. if (this.o) this.o -= 1;
  45. };
  46. Queue.prototype.front = function() {
  47. return this.q.front();
  48. };
  49. return Queue;
  50. }(Base);
  51. export default Queue;