Java Using ArrayList only
Complexity\n- Time complexity: Operations with mid are of O(N)\n\n# Code\n\nclass FrontMiddleBackQueue {\n\n    ArrayList<Integer> list;\n    public FrontMiddle
# Complexity\n- Time complexity: Operations with mid are of O(N)\n\n# Code\n```\nclass FrontMiddleBackQueue {\n\n    ArrayList<Integer> list;\n    public FrontMiddleBackQueue() {\n        list = new ArrayList<>();\n    }\n\n    public void pushFront(int val) {\n        if (list.isEmpty()) list.add(val);\n        else list.add(0, val);\n    }\n\n    public void pushMiddle(int val) {\n        if (list.isEmpty()) list.add(val);\n        else list.add(list.size() / 2, val);\n    }\n\n    public void pushBack(int val) {\n        list.add(val);\n    }\n\n    public int popFront() {\n        return list.isEmpty() ? -1 : list.remove(0);\n    }\n\n    public int popMiddle() {\n        return list.isEmpty() ? -1 : list.size() % 2 == 0 ? list.remove(list.size() / 2 - 1) : list.remove(list.size() / 2);\n    }\n\n    public int popBack() {\n        return list.isEmpty() ? -1 : list.remove(list.size() - 1);\n    }\n}\n```
['Java']