{"ScriptPreparationCode":"class LinkedListQueue {\r\n constructor() {\r\n this.length = 0;\r\n this.head = undefined;\r\n this.tail = undefined;\r\n }\r\n\r\n enqueue(value) {\r\n this.enqueueNode(value);\r\n }\r\n\r\n dequeue() {\r\n return this.dequeueNode();\r\n }\r\n\r\n dequeueFromTail() {\r\n return this.dequeueNodeFromTail();\r\n }\r\n\r\n size() {\r\n return this.length;\r\n }\r\n\r\n getHead() {\r\n return this.head;\r\n }\r\n\r\n getTail() {\r\n return this.tail;\r\n }\r\n\r\n enqueueNode(value) {\r\n const node = {\r\n value,\r\n next: undefined,\r\n prev: this.tail\r\n };\r\n\r\n if (!this.head) {\r\n this.head = node;\r\n this.tail = node;\r\n } else {\r\n this.tail.next = node;\r\n this.tail = node;\r\n }\r\n\r\n this.length \u002B= 1;\r\n }\r\n\r\n dequeueNode() {\r\n if (this.head) {\r\n const value = this.head.value;\r\n this.head = this.head.next;\r\n\r\n if (this.head) {\r\n this.head.prev = undefined;\r\n } else {\r\n this.tail = undefined;\r\n }\r\n\r\n this.length -= 1;\r\n return value;\r\n }\r\n\r\n return undefined;\r\n }\r\n\r\n dequeueNodeFromTail() {\r\n if (this.tail) {\r\n const value = this.tail.value;\r\n this.tail = this.tail.prev;\r\n\r\n if (this.tail) {\r\n this.tail.next = undefined;\r\n } else {\r\n this.head = undefined;\r\n }\r\n\r\n this.length -= 1;\r\n return value;\r\n }\r\n\r\n return undefined;\r\n }\r\n}\r\n\r\n\r\nclass DoubleArrayQueue {\r\n constructor() {\r\n this.input = [];\r\n this.output = [];\r\n }\r\n\r\n enqueue(element) {\r\n this.input.push(element);\r\n }\r\n\r\n dequeue() {\r\n if (this.output.length === 0) {\r\n this.pivot();\r\n }\r\n return this.output.pop();\r\n }\r\n\r\n dequeueFromTail() {\r\n if (this.input.length === 0) {\r\n this.pivot();\r\n }\r\n return this.input.pop();\r\n }\r\n\r\n pivot() {\r\n this.output = this.input.reverse();\r\n this.input = [];\r\n }\r\n\r\n isEmpty() {\r\n return this.input.length === 0 \u0026\u0026 this.output.length === 0;\r\n }\r\n}\r\n\r\n\r\nclass Queue {\r\n constructor() {\r\n this.queue = new Map();\r\n this.head = 0;\r\n this.tail = 0;\r\n }\r\n\r\n enqueue(item) {\r\n this.queue.set(this.tail, item);\r\n this.tail\u002B\u002B;\r\n }\r\n\r\n dequeue() {\r\n if (this.head === this.tail) return;\r\n\r\n const value = this.queue.get(this.head);\r\n this.queue.delete(this.tail);\r\n this.head\u002B\u002B;\r\n\r\n return value;\r\n }\r\n \r\n dequeueFromTail() {\r\n if (this.head === this.tail) return;\r\n this.tail--;\r\n const value = this.queue.get(this.tail);\r\n this.queue.delete(this.tail);\r\n return value;\r\n }\r\n\r\n size() {\r\n return this.tail - this.head;\r\n }\r\n}\r\n\r\nvar doubleQ = new DoubleArrayQueue()\r\nvar linkedListQ = new LinkedListQueue()\r\nvar queue = new Queue()\r\nvar queueSize = 100000\r\n","TestCases":[{"Name":"Double Array enque","Code":"for(let i = 0; i \u003C queueSize; i\u002B\u002B) {\r\n doubleQ.enqueue(i)\r\n}","IsDeferred":false},{"Name":"Linked List enque","Code":"for(let i = 0; i \u003C queueSize; i\u002B\u002B) {\r\n linkedListQ.enqueue(i)\r\n}","IsDeferred":false},{"Name":"Queue enqeue","Code":"for(let i = 0; i \u003C queueSize; i\u002B\u002B) {\r\n queue.enqueue(i)\r\n}","IsDeferred":false},{"Name":"Array deque","Code":"for(let i = 0; i \u003C queueSize; i\u002B\u002B) {\r\n doubleQ.dequeue()\r\n}","IsDeferred":false},{"Name":"LinkedList deque","Code":"for(let i = 0; i \u003C queueSize; i\u002B\u002B) {\r\n linkedListQ.dequeue()\r\n}","IsDeferred":false},{"Name":"Queue deque","Code":"for(let i = 0; i \u003C queueSize; i\u002B\u002B) {\r\n queue.dequeue()\r\n}","IsDeferred":false},{"Name":"Array deque from Tails","Code":"for(let i = 0; i \u003C queueSize; i\u002B\u002B) {\r\n doubleQ.dequeueFromTail()\r\n}","IsDeferred":false},{"Name":"Linked from Tail","Code":"for(let i = 0; i \u003C queueSize; i\u002B\u002B) {\r\n linkedListQ.dequeueFromTail()\r\n}","IsDeferred":false},{"Name":"Queue from tail","Code":"for(let i = 0; i \u003C queueSize; i\u002B\u002B) {\r\n queue.dequeueFromTail()\r\n}","IsDeferred":false}]}