C++ Solution | Runtime: 24ms | Faster than 99% | Using Doubly Linked List
\nclass FrontMiddleBackQueue {\npublic:\n    // Double LinkList Node to implement Front Middle Back Queue\n    class ListNode {\n    public:\n        int val;\n
```\nclass FrontMiddleBackQueue {\npublic:\n    // Double LinkList Node to implement Front Middle Back Queue\n    class ListNode {\n    public:\n        int val;\n        ListNode *next, *prev;\n        ListNode(int x) {\n            val = x;\n            next = prev = NULL;\n        }\n    };\n    // Class members\n    ListNode *head, *middle, *tail;\n    int size;\n    // Constructor\n    FrontMiddleBackQueue() {\n        head = middle = tail = NULL;\n        size = 0;\n    }\n    // From given testcase, pushFront pushes a val at front of current front\n    void pushFront(int val) {\n        if (!size) head = middle = tail = new ListNode(val);\n        else {\n            ListNode *nd = head;\n            // cout << "front push: " << size << " " << head << " " << middle << " " << tail << "\\n";\n            // Push new node at front\n            head = new ListNode(val);\n            head->next = nd;\n            // Update old head\n            nd->prev = head;\n            // if old size is odd only then shift the middle\n            if (size & 1) middle = middle->prev;\n        }\n        size++;\n    }\n    // From given testcase, pushMiddle pushes a val at future middle\n    void pushMiddle(int val) {\n        if (!size) head = middle = tail = new ListNode(val);\n        else if (size == 1) return pushFront(val);\n        else {\n            // if old size is even then first shift/ update middle\n            if (!(size & 1)) middle = middle->next;\n            // cout << "mid push: " << size << " " << head << " " << middle << " " << tail << "\\n";\n            ListNode *nd = new ListNode(val);\n            // Add new node at back of current middle\n            middle->prev->next = nd;\n            nd->prev = middle->prev;\n            nd->next = middle;\n            middle->prev = nd;\n            // Update middle\n            middle = middle->prev;\n        }\n        size++;\n    }\n    // From given testcase, pushBack pushes a val at front of current back\n    void pushBack(int val) {\n        if (!size) head = middle = tail = new ListNode(val);\n        else {\n            // cout << "back push: " << size << " " << head << " " << middle << " " << tail << "\\n";\n            ListNode *nd = tail;\n            // Push new node at back\n            tail = new ListNode(val);\n            tail->prev = nd;\n            // Update old tail\n            nd->next = tail;\n            // if old size is even only then Update the middle\n            if (!(size & 1)) middle = middle->next;\n        }\n        size++;\n    }\n    // From given testcase, popFront popes a val at current front\n    int popFront() {\n        if (!size) return -1;\n        int front = head->val;\n        if (size == 1) head = tail = middle = NULL;\n        else {\n            // cout << "pop front: " << size << " " << head << " " << middle << " " << tail << "\\n";\n            // if old size is even only then Update the middle\n            if (!(size & 1)) middle = middle->next;\n            // Update head\n            head = head->next;\n            head->prev = NULL;\n        }\n        size--;\n        return front;\n    }\n    // From given testcase, popMiddle popes a val at current mid\n    int popMiddle() {\n        if (!size) return -1;\n        int mid = middle->val;\n        if (size == 1) head = middle = tail = NULL;\n        else if (size == 2) return popFront();\n        else {\n            // cout << "pop mid: " << size << " " << head << " " << middle << " " << tail << "\\n";\n            // Update middle\'s prev and next\n            middle->prev->next = middle->next;\n            middle->next->prev = middle->prev;\n            // Update middle as per old size\n            if (size & 1) middle = middle->prev;\n            else middle = middle->next;\n        }\n        size--;\n        return mid;\n    }\n    // From given testcase, popBack popes a val at current back\n    int popBack() {\n        if (!size) return -1;\n        int back = tail->val;\n        if (size == 1) head = middle = tail = NULL;\n        else {\n            // cout << "pop back: " << size << " " << head << " " << middle << " " << tail << "\\n";\n            // Update tail\n            tail = tail->prev;\n            tail->next = NULL;\n            // if old size is odd only then Update the middle\n            if (size & 1) middle = middle->prev;\n        }\n        size--;\n        return back;\n    }\n};\n```
[]