c++ easy o(1) - time lagega but samaj me aaega
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nstruct Node{\n    int val;\n    Node* next;\n    Node* prev;\n    Node(int x){\n        val=x;\n        next=prev=NULL;\n    }\n};\n Node* createNode(int x){\n     return new Node(x);\n }\n\nclass FrontMiddleBackQueue {\n\npublic:\nNode* head=NULL;\nNode* tail=NULL;\nNode* mid=NULL;\nint size=0;\n    FrontMiddleBackQueue() {\n        \n    }\n    \n    void pushFront(int val) {\n        Node* newNode= createNode(val);\n        if(size==0){\n            head=tail=mid=newNode;\n        }else{\n                newNode->next=head;\n                head->prev=newNode;\n                newNode->prev=NULL;\n                head=head->prev;\n        }\n        size++;\n        if(size%2==0){\n            mid=mid->prev;\n        }\n    }\n   \n    \n     \n    void pushMiddle(int val) {\n        Node * newNode = createNode(val);\n        if(size==0)\n            head = tail = mid = newNode;\n        else\n        {\n            if(size%2==0)\n            {\n                newNode->next = mid->next;\n                newNode->prev = mid;\n                mid->next->prev = newNode;\n                mid->next = newNode;\n                mid = mid->next;\n            }\n            else \n            {\n                newNode->next = mid;\n                newNode->prev = mid->prev;\n                if(mid->prev)\n                    mid->prev->next = newNode;\n                mid->prev = newNode;\n                mid = mid->prev;\n                if(size==1)\n                    head = mid;\n            }\n        }\n        size++;\n    }\n    \n     void pushBack(int val) {\n        Node * newNode = createNode(val);\n        if(size==0)\n            head = tail = mid = newNode;\n        \n        else\n        {\n            newNode->prev = tail;\n            newNode->next = NULL;\n            tail->next = newNode;\n            tail = tail->next;\n        }\n        size++;\n        if(size%2!=0 && size!=1)\n            mid = mid->next;\n    }\n    \n    int popFront() {\n\n        if(size==0) return -1;\n\n        int ans = head->val;\n        Node * toDel = head;;\n        if(size==1)\n        {\n            head = mid = tail = NULL;\n        }\n        else\n        {\n            head->next->prev = NULL;\n            head = head->next;\n            if(size%2==0)\n                mid = mid->next;\n        }\n        delete toDel;\n        size--;\n        return ans;\n    }\n    \n  int popMiddle() {\n        if(size==0) return -1;\n\n        int ans = mid->val;\n        Node * toDel = mid;\n        if(size==1)\n        {\n            head = mid = tail = NULL;\n        }\n        else\n        {\n            mid->next->prev = mid->prev;\n            if(mid->prev)\n                mid->prev->next = mid->next;\n\n            if(size%2!=0) //odd no of elements\n                mid = mid->prev;\n            else\n                mid = mid->next;\n\n            if(size==2)\n                head = mid;\n\n        }\n        delete toDel;\n        size--;\n        return ans;\n    }\n    \n      int popBack() {\n\n        if(size==0) return -1;\n\n        int ans = tail->val;\n        Node *toDel = tail;\n        \n        if(size==1)\n            head = mid = tail = NULL;\n        else\n        {\n            tail->prev->next = NULL;\n            tail = tail->prev;\n            if(size%2!=0)\n                mid = mid->prev;\n            \n        }\n        delete toDel;\n        size--;\n        return ans;\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```
['C++']