100% BEST SOLUTION JAVA USING ONLY ONE LINKEDLIST
JAVA BASED BEST SOLUTION\n Describe your first thoughts on how to solve this problem. \njust using the collection - methods of linkedlist\n\n\n# Approach\n Desc
### JAVA BASED BEST SOLUTION\n<!-- Describe your first thoughts on how to solve this problem. -->\njust using the collection - methods of linkedlist\n\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nJust use the methods of LinkedList.\n\n# Complexity\n- Time complexity:pushFront: O(1)\npushMiddle: O(n)\npushBack: O(1)\npopFront: O(1)\npopMiddle: O(n)\npopBack: O(1)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: The space complexity is O(n), where n is the number of elements in the queue.\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass FrontMiddleBackQueue {\n    LinkedList<Integer>queue;\n    public FrontMiddleBackQueue() {\n        queue = new LinkedList<>();\n    }\n    \n    public void pushFront(int val) {\n        queue.add(0,val);\n    }\n    \n    public void pushMiddle(int val) {\n        int n = queue.size();\n        int mid = (n) / 2;\n        queue.add(mid , val);     \n    }\n    \n    public void pushBack(int val) {\n        queue.addLast(val);\n    }\n    \n    public int popFront() {\n        if(queue.isEmpty())\n        {\n            return -1;\n        }\n        return queue.removeFirst();\n    }\n    \n    public int popMiddle() {\n        if(queue.isEmpty())\n        {\n            return -1;\n        }\n        int n = queue.size();\n        int mid = (n - 1) / 2;\n        int pm = queue.remove(mid);\n        return pm;\n    }\n    \n    public int popBack() {\n         if(queue.isEmpty())\n        {\n            return -1;\n        }\n       int pb =  queue.removeLast();\n       return pb;\n    }\n}\n\n/**\n * Your FrontMiddleBackQueue object will be instantiated and called as such:\n * FrontMiddleBackQueue obj = new FrontMiddleBackQueue();\n * obj.pushFront(val);\n * obj.pushMiddle(val);\n * obj.pushBack(val);\n * int param_4 = obj.popFront();\n * int param_5 = obj.popMiddle();\n * int param_6 = obj.popBack();\n */\n```
['Java']