C++, std::list only, no pointers
The idea is straightforward -- take std::list and use it\'s methods for front/back.\nAdditionally, implement middle element functionality by using iterator.\n\n
The idea is straightforward -- take `std::list` and use it\'s methods for front/back.\nAdditionally, implement middle element functionality by using iterator.\n\n```C++\nclass FrontMiddleBackQueue {\n    list<int> l;\n    decltype(l)::iterator m;\npublic:\n    FrontMiddleBackQueue() {\n    }\n    \n    void pushFront(int val) {\n        l.push_front(val);\n        if (l.size() == 1)\n            m = l.begin();\n        else if (l.size()%2 == 0) {\n            --m;\n        }\n    }\n    \n    void pushMiddle(int val) {\n        if (l.size() == 0) {\n            pushFront(val);\n        } else {\n\t\t\t// insert places the new element before iterator\n\t\t    // this is desired for odd case but not desired for even\n            if (l.size()%2 == 0)\n                ++m;\n            m = l.insert(m, val);\n        }\n    }\n    \n    void pushBack(int val) {\n        l.push_back(val);\n        if (l.size() == 1)\n            m = l.begin();\n        else if (l.size()%2 == 1) {\n            ++m;\n        }\n    }\n    \n    int popFront() {\n        if (l.size() == 0) return -1;\n        int res = l.front();\n        if (l.size()%2 == 0) {\n            ++m;\n        }\n        l.pop_front();\n        return res;\n    }\n    \n    int popMiddle() {\n        if (l.size() == 0) return -1;\n        int res = *m;\n        m = l.erase(m);\n        if (l.size() % 2 == 0 && l.size() != 0)\n            --m;\n        return res;\n    }  \n    \n    int popBack() {\n         if (l.size() == 0) return -1;\n        int res = l.back();\n\n        if (l.size()%2 == 1) {\n            --m;\n        }\n        l.pop_back();\n        return res;\n    }\n};\n```
['C']