Stack.js 1.5 KB

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