Modern C++ Deque Solution
Runtime: 36 ms, faster than 61.47% of C++ online submissions for Design Front Middle Back Queue.\nMemory Usage: 20.2 MB, less than 52.91% of C++ online submissi
**Runtime:** 36 ms, faster than 61.47% of C++ online submissions for Design Front Middle Back Queue.\n**Memory Usage:** 20.2 MB, less than 52.91% of C++ online submissions for Design Front Middle Back Queue.\n\n**Note:**\nThe important caveat to remember with this algorithm is that popping an element from the middle index is to be done using `vec.size()-1 / 2` whereas when pushing a value to the middle index we use `vec.size()/2`. Happy coding!\n\n```\n#include <deque>\n#include <algorithm>\n\nclass FrontMiddleBackQueue {\npublic:\n    FrontMiddleBackQueue() {\n        \n    }\n    \n    void pushFront(int val) {\n        vec.push_front(val);\n    }\n    \n    void pushMiddle(int val) {\n        vec.insert(vec.begin()+vec.size()/2, val);\n    }\n    \n    void pushBack(int val) {\n        vec.push_back(val);\n    }\n    \n    int popFront() {\n        \n        if(!vec.size()){ return -1; }\n        const int front = vec.front();\n        vec.pop_front();\n        return front;\n    }\n    \n    int popMiddle() {\n        if(!vec.size()){ return -1; }\n        const int mid = vec.at(getMiddleIndex());\n        vec.erase(vec.begin()+getMiddleIndex());\n        return mid;\n    }\n    \n    int popBack() {\n        if(!vec.size()){ return -1; }\n        const int back = vec.back();\n        vec.pop_back();\n        return back;\n    }\n    \nprivate:\n    \n    size_t getMiddleIndex(){\n\t\treturn (std::max(0, static_cast<int>(vec.size()-1)) / 2);\n    }\n    \n    std::deque<int> vec;\n};\n
[]