{"ScriptPreparationCode":"var CircularQueue = class CircularQueue {\r\n constructor(growth) {\r\n this.growth = growth\r\n this.data = new Array(4);\r\n\r\n // \uD56D\uC0C1 \uAEBC\uB0BC \uC6D0\uC18C\uB97C \uAC00\uB9AC\uCF1C\uC57C \uD568\r\n this.head = 0;\r\n\r\n // \uD56D\uC0C1 \uC0C8\uB85C\uC6B4 \uC6D0\uC18C\uB97C \uB123\uC744 \uACF5\uAC04\uC744 \uAC00\uB9AC\uCF1C\uC57C \uD568\r\n this.tail = 0;\r\n this.size = 0;\r\n }\r\n\r\n grow() {\r\n const length = this.data.length;\r\n this.data = this.data\r\n .slice(this.head, length)\r\n .concat(this.data.slice(0, this.head))\r\n .concat(new Array(Math.max(1, Math.ceil(length * this.growth))));\r\n this.head = 0;\r\n this.tail = length;\r\n }\r\n\r\n push(el) {\r\n this.data[this.tail] = el;\r\n this.tail = (this.tail \u002B 1) % this.data.length;\r\n if (this.tail === this.head) {\r\n this.grow();\r\n }\r\n this.size \u002B= 1;\r\n }\r\n\r\n pop() {\r\n if (this.size \u003C= 0) return undefined;\r\n const result = this.data[this.head];\r\n this.head = (this.head \u002B 1) % this.data.length;\r\n this.size -= 1;\r\n return result;\r\n }\r\n\r\n front() {\r\n if (this.size \u003C= 0) return undefined;\r\n return this.data[this.head];\r\n }\r\n}\r\n\r\nvar LinkedListQueue = class LinkedListQueue {\r\n constructor() {\r\n this.head = null;\r\n this.tail = null;\r\n this.size = 0;\r\n }\r\n\r\n push(el) {\r\n const newNode = {\r\n next: null,\r\n value: el\r\n };\r\n if (this.tail) {\r\n this.tail.next = newNode;\r\n } else {\r\n this.head = newNode;\r\n }\r\n this.tail = newNode;\r\n this.size \u002B= 1;\r\n }\r\n\r\n pop() {\r\n const result = this.head?.value;\r\n this.head = this.head?.next;\r\n if (!this.head) {\r\n this.tail = null;\r\n }\r\n this.size = Math.max(0, this.size - 1);\r\n return result;\r\n }\r\n\r\n front() {\r\n return this.head?.value;\r\n }\r\n\r\n debug() {\r\n const arr = [];\r\n let node = this.head;\r\n while (node) {\r\n arr.push(node.value);\r\n node = node.next;\r\n }\r\n console.log(arr.join(\u0022, \u0022));\r\n }\r\n}\r\n\r\nconst N = 1000000\r\nconst operations = new Array(N)\r\nfor (let n = 0; n \u003C N; \u002B\u002Bn) {\r\n operations[n] = (n ** 2 \u002B 3 * n) % 2\r\n}\r\n\r\nfunction test(q) {\r\n for (const op of operations) {\r\n if (op) {\r\n q.push(Math.random())\r\n } else {\r\n q.pop()\r\n }\r\n }\r\n}","TestCases":[{"Name":"CircularQueue (rate = 1)","Code":"test(new CircularQueue(1))","IsDeferred":false},{"Name":"LinkedListQueue","Code":"test(new LinkedListQueue())","IsDeferred":false},{"Name":"CircularQueue (rate = 0.5)","Code":"test(new CircularQueue(0.5))","IsDeferred":false},{"Name":"CircularQueue (rate = 0.25)","Code":"test(new CircularQueue(0.25))","IsDeferred":false}]}