Using Double Linked List. EACH OPERATION WITH: O(1) time
\n\tThis solution uses Double Linked List.\n\tSave three pointer: \n\t\t* front\n\t\t* middle\n\t\t* back\n\tworking with front and back nodes i trivial, but we
```\n\tThis solution uses Double Linked List.\n\tSave three pointer: \n\t\t* front\n\t\t* middle\n\t\t* back\n\tworking with front and back nodes i trivial, but we also update middle pointer in ieach operation, so we have O(1) time for each operation.\n```\n\tclass FrontMiddleBackQueue {\n\tpublic:\n\t\tstruct FMBQueueNode { // Front Middle Back Queue Node\n\t\t\tint value;\n\t\t\tFMBQueueNode *prev, *next;\n\n\t\t\tFMBQueueNode(int _value, FMBQueueNode *_prev = NULL, FMBQueueNode *_next = NULL) {\n\t\t\t\tvalue = _value;\n\t\t\t\tprev = _prev;\n\t\t\t\tnext = _next;\n\t\t\t}\n\t\t};\n\n\t\tFMBQueueNode *frontNode, *middleNode, *backNode;\n\t\tint count;  // number elements in Front Middle Back Queue\n\n\t\tFrontMiddleBackQueue() {\n\t\t\tfrontNode = NULL;\n\t\t\tmiddleNode = NULL;\n\t\t\tbackNode = NULL;\n\n\t\t\tcount = 0;\n\t\t}\n\n\t\tvoid pushFront(int val) {\n\t\t\tFMBQueueNode *newNode = new FMBQueueNode(val);\n\n\t\t\tif(count == 0)\n\t\t\t\tpushFirstNode(newNode);\n\t\t\telse {\n\t\t\t\tnewNode->next = frontNode;\n\t\t\t\tfrontNode->prev = newNode;\n\t\t\t\tfrontNode = newNode;\n\n\t\t\t\tif(count % 2 == 1)\n\t\t\t\t\tmiddleNode = middleNode->prev;\n\t\t\t}\n\n\t\t\tcount += 1;\n\t\t}\n\n\t\tvoid pushMiddle(int val) {\n\t\t\tFMBQueueNode *newNode = new FMBQueueNode(val);\n\n\t\t\tif(isEmpty())\n\t\t\t\tpushFirstNode(newNode);\n\t\t\telse {\n\t\t\t\tif(count == 1) {\n\t\t\t\t\tnewNode->next = frontNode;\n\t\t\t\t\tfrontNode->prev = newNode;\n\t\t\t\t\tfrontNode = newNode;\n\t\t\t\t\tmiddleNode = newNode;\n\t\t\t\t} else {\n\t\t\t\t\tif(count % 2 == 0) {\n\t\t\t\t\t\tnewNode->next = middleNode->next;\n\t\t\t\t\t\tmiddleNode->next->prev = newNode;\n\t\t\t\t\t\tmiddleNode->next = newNode;\n\t\t\t\t\t\tnewNode->prev = middleNode;\n\t\t\t\t\t\tmiddleNode = newNode;\n\t\t\t\t\t} else {\n\t\t\t\t\t\tmiddleNode->prev->next = newNode;\n\t\t\t\t\t\tnewNode->prev = middleNode->prev;\n\t\t\t\t\t\tnewNode->next = middleNode;\n\t\t\t\t\t\tmiddleNode->prev = newNode;\n\t\t\t\t\t\tmiddleNode = newNode;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tcount += 1;\n\t\t}\n\n\t\tvoid pushBack(int val) {\n\t\t\tFMBQueueNode *newNode = new FMBQueueNode(val);\n\n\t\t\tif(isEmpty())\n\t\t\t\tpushFirstNode(newNode);\n\t\t\telse {\n\t\t\t\tbackNode->next = newNode;\n\t\t\t\tnewNode->prev = backNode;\n\t\t\t\tbackNode = newNode;\n\n\t\t\t\tif(count % 2 == 0) {\n\t\t\t\t\tmiddleNode = middleNode->next;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tcount += 1;\n\t\t}\n\n\t\tint popFront() {\n\t\t\tif(isEmpty()) return -1;\n\n\t\t\tint front = frontNode->value;\n\t\t\tFMBQueueNode *toDelete = frontNode;\n\n\t\t\tif(count == 1) {\n\t\t\t\tpopOnlyNode();\n\t\t\t} else {\n\t\t\t\tfrontNode = frontNode->next;\n\t\t\t\tfrontNode->prev = NULL;\n\n\t\t\t\tif(count % 2 == 0) \n\t\t\t\t\tmiddleNode = middleNode->next;\n\t\t\t}\n\n\t\t\tdelete toDelete;\n\t\t\tcount -= 1;    \n\n\t\t\treturn front;\n\t\t}\n\n\n\t\tint popMiddle() {\n\t\t\tif(isEmpty()) return -1;\n\n\t\t\tint middle = middleNode->value;\n\t\t\tFMBQueueNode *toDelete = middleNode;\n\n\t\t\tif(count == 1) {\n\t\t\t\tpopOnlyNode();\n\t\t\t} else if(count == 2) { \n\t\t\t\tfrontNode = frontNode->next;\n\t\t\t\tbackNode->prev = NULL;\n\t\t\t\tmiddleNode = middleNode->next;\n\t\t\t} else {\n\t\t\t\tmiddleNode->prev->next = middleNode->next;\n\t\t\t\tmiddleNode->next->prev = middleNode->prev;\n\t\t\t\tif(count % 2 == 1)// isOdd\n\t\t\t\t\tmiddleNode = middleNode->prev;\n\t\t\t\telse // count % 2 == 0 -> isEven\n\t\t\t\t\tmiddleNode = middleNode->next;\n\t\t\t}\n\n\t\t\tdelete toDelete;\n\t\t\tcount -= 1;\n\n\t\t\treturn middle;\n\t\t}\n\n\t\tint popBack() {\n\t\t\tif(isEmpty()) return -1;\n\n\t\t\tint back = backNode->value;\n\t\t\tFMBQueueNode *toDelete = backNode;\n\n\t\t\tif(count == 1)\n\t\t\t\tpopOnlyNode();\n\t\t\telse {\n\t\t\t\tbackNode = backNode->prev;\n\t\t\t\tbackNode->next = NULL;\n\t\t\t\tif(count % 2 == 1)\n\t\t\t\t\tmiddleNode = middleNode->prev;\n\t\t\t}\n\n\t\t\tdelete toDelete;\n\t\t\tcount -= 1;\n\n\t\t\treturn back;\n\t\t}\n\n\tprivate:\n\t\tbool isEmpty() {\n\t\t\treturn count == 0;\n\t\t}\n\n\t\tvoid pushFirstNode(FMBQueueNode *newNode) {\n\t\t\tfrontNode = newNode;\n\t\t\tmiddleNode = newNode;\n\t\t\tbackNode = newNode;\n\t\t}\n\n\t\tvoid popOnlyNode() {\n\t\t\tfrontNode = NULL;\n\t\t\tmiddleNode = NULL;\n\t\t\tbackNode = NULL;\n\t\t}\n\t};\n
['Linked List', 'C', 'Simulation', 'Doubly-Linked List', 'C++']