c++ | easy | fast
\n\n# Code\n\n//from omhardaha1\nstruct DLL\n{\n    int val;\n    DLL *next;\n    DLL *prev;\n    DLL() : val(0), next(nullptr), prev(nullptr) {}\n    DLL(int x
\n\n# Code\n```\n//from omhardaha1\nstruct DLL\n{\n    int val;\n    DLL *next;\n    DLL *prev;\n    DLL() : val(0), next(nullptr), prev(nullptr) {}\n    DLL(int x) : val(x), next(nullptr), prev(nullptr) {}\n};\n\nclass FrontMiddleBackQueue\n{\npublic:\n    int curSize = 0;\n    DLL *LL = nullptr;\n    DLL *front = nullptr;\n    DLL *middle = nullptr;\n    DLL *rear = nullptr;\n\n    FrontMiddleBackQueue() {}\n\n    void pushFront(int value)\n    {\n        if (curSize == 0)\n        {\n            LL = new DLL(value);\n            front = LL;\n            rear = LL;\n            middle = LL;\n        }\n        else\n        {\n            DLL *D = new DLL(value);\n            D->next = front;\n            front->prev = D;\n            front = D;\n            if (curSize & 1)\n            {\n                middle = middle->prev;\n            }\n        }\n        curSize++;\n    }\n\n    void pushMiddle(int value)\n    {\n        if (curSize == 0)\n        {\n            LL = new DLL(value);\n            front = LL;\n            rear = LL;\n            middle = LL;\n        }\n        else if (curSize == 1)\n        {\n\n            DLL *D = new DLL(value);\n            D->next = middle;\n            middle->prev = D;\n            middle = D;\n            front = D;\n        }\n        else\n        {\n            if (curSize & 1)\n            {\n                DLL *D = new DLL(value);\n                D->next = middle;\n                D->prev = middle->prev;\n                middle->prev->next = D;\n                middle->prev = D;\n                middle = D;\n            }\n            else\n            {\n                DLL *D = new DLL(value);\n                D->next = middle->next;\n                D->prev = middle;\n                middle->next = D;\n                D->next->prev = D;\n                middle = D;\n            }\n        }\n        curSize++;\n    }\n\n    void pushBack(int value)\n    {\n        if (curSize == 0)\n        {\n            LL = new DLL(value);\n            front = LL;\n            rear = LL;\n            middle = LL;\n        }\n        else\n        {\n            rear->next = new DLL(value);\n            rear->next->prev = rear;\n            rear = rear->next;\n            if (!(curSize & 1))\n            {\n                middle = middle->next;\n            }\n        }\n        curSize++;\n    }\n\n    int popFront()\n    {\n        if (!curSize)\n        {\n            return -1;\n        }\n        int v = front->val;\n        if (curSize == 1)\n        {\n            LL = rear = front = middle = nullptr;\n        }\n        else\n        {\n            if (!(curSize & 1))\n            {\n                middle = middle->next;\n            }\n            front = front->next;\n            front->prev = nullptr;\n        }\n        curSize--;\n        return v;\n    }\n\n    int popMiddle()\n    {\n        if (!curSize)\n        {\n            return -1;\n        }\n        int v = middle->val;\n\n        if (curSize == 1)\n        {\n            LL = rear = front = middle = nullptr;\n        }\n        else if (curSize == 2)\n        {\n            LL = rear = front = middle = front->next;\n        }\n        else\n        {\n            middle->next->prev = middle->prev;\n            middle->prev->next = middle->next;\n            if (curSize & 1)\n            {\n                middle = middle->prev;\n            }\n            else\n            {\n                middle = middle->next;\n            }\n        }\n        curSize--;\n        return v;\n    }\n\n    int popBack()\n    {\n        if (!curSize)\n        {\n            return -1;\n        }\n        int v = rear->val;\n        if (curSize == 1)\n        {\n            LL = rear = front = middle = nullptr;\n        }\n        else\n        {\n            if (curSize & 1)\n            {\n                middle = middle->prev;\n            }\n            rear = rear->prev;\n            rear->next = nullptr;\n        }\n        curSize--;\n        return v;\n    }\n};\n```
['C++']