✅✅Faster || Easy To Understand || C++ Code
Using deque\n\n Time Complexity :- O(N) for insert and pop from middle and O(1) for other operations\n\n Space Complexity :- O(N)\n\n\nclass FrontMiddleBackQueu
* ***Using deque***\n\n* ***Time Complexity :- O(N) for insert and pop from middle and O(1) for other operations***\n\n* ***Space Complexity :- O(N)***\n\n```\nclass FrontMiddleBackQueue {\npublic:\n    \n    deque<int> dq;\n    \n    FrontMiddleBackQueue() {\n        \n    }\n    \n    void pushFront(int val) {\n        \n        dq.push_front(val);\n    }\n    \n    void pushMiddle(int val) {\n        \n        int middle_pos = dq.size() / 2;\n        \n        // iterator to middle position\n        \n        auto it = dq.begin() + middle_pos;\n        \n        // insert at middle position\n        \n        dq.insert(it, val);\n    }\n    \n    void pushBack(int val) {\n        \n        dq.push_back(val);\n    }\n    \n    int popFront() {\n        \n        // if dq is empty\n        \n        if(dq.size() == 0)\n            return -1;\n        \n        int val = dq.front();\n        \n        dq.pop_front();\n        \n        return val;\n    }\n    \n    int popMiddle() {\n        \n        // if deque is empty\n        \n        if(dq.size() == 0)\n            return -1;\n        \n        // find the middle position of dq\n        \n        int middle_pos = dq.size() / 2;\n        \n        // if size of dq is even, then take front most as middle so decrement the middle_pos\n        \n        if(dq.size() % 2 == 0)\n        {\n            middle_pos--;\n        }\n        \n        // find the iterator to the middle position\n        \n        auto it = dq.begin() + middle_pos;\n        \n        // store the value in val\n        \n        int val = *it;\n        \n        // erase the middle element\n        \n        dq.erase(it);\n        \n        return val;\n    }\n    \n    int popBack() {\n        \n        // if dq is empty\n        \n        if(dq.size() == 0)\n            return -1;\n        \n        int val = dq.back();\n        \n        dq.pop_back();\n        \n        return val;\n    }\n};\n```
['Queue', 'C', 'C++']