✅✅✅ || 99% faster || C++ solution using Linked List
Please do upvote \u2B06\uFE0F my solution to keep me motivated :)\nQuestions ?? I am super active at the comments section.\n# Code\n\nclass FrontMiddleBackQueue
***Please do upvote \u2B06\uFE0F my solution to keep me motivated :)***\n***Questions ?? I am super active at the comments section.***\n# Code\n```\nclass FrontMiddleBackQueue {\nprivate:\n    ListNode* head;\npublic:\n    FrontMiddleBackQueue() {\n        head = NULL;\n    }\n    \n    void pushFront(int val) {\n        ListNode* n = new ListNode(val);\n        n->next = head;\n        head = n;\n        return;\n    }\n    \n    void pushMiddle(int val) {\n        if(head==NULL || head->next==NULL) {\n            pushFront(val);\n            return;\n        }\n        // else if(head->next->next==NULL) {\n        //     ListNode* n = new ListNode(val);\n        //     n->next = head->next;\n        //     head->next = n;\n        //     return;\n        // }\n        ListNode* p = NULL;\n        ListNode* s = head;\n        ListNode* f = head->next;\n        while(f && f->next) {\n            p = s;\n            s = s->next;\n            f = f->next->next;\n        }\n        ListNode* n = new ListNode(val);\n        if(f) {\n            n->next = s->next;\n            s->next = n;\n            return;\n        }\n        else {\n            n->next = s;\n            p->next = n;\n            return;\n        }\n    }\n    \n    void pushBack(int val) {\n        if(head==NULL) {\n            head = new ListNode(val);\n            return;\n        }\n        ListNode* t = head;\n        while(t->next) {\n            t = t->next;\n        }\n        t->next = new ListNode(val);\n        return;\n    }\n    \n    int popFront() {\n        if(head==NULL) {\n            return -1;\n        }\n        int ans = head->val;\n        head = head->next;\n        return ans;\n    }\n    \n    int popMiddle() {\n        if(head==NULL) {\n            return -1;\n        }\n        if(head->next==NULL || head->next->next==NULL) {\n            int ans = head->val;\n            head = head->next;\n            return ans;\n        }\n        ListNode* p = NULL;\n        ListNode* s = head;\n        ListNode* f = head->next;\n        while(f && f->next) {\n            p = s;\n            s = s->next;\n            f = f->next->next;\n        }\n        int ans = s->val;\n        p->next = s->next;\n        delete s;\n        return ans;\n    }\n    \n    int popBack() {\n        if(head==NULL) {\n            return -1;\n        }\n        else if(head->next==NULL) {\n            int ans = head->val;\n            head = head->next;\n            return ans;\n        }\n        int ans;\n        ListNode* t = head;\n        ListNode* p = NULL;\n        while(t->next) {\n            p = t;\n            t = t->next;\n        }\n        ans = t->val;\n        p->next = NULL;\n        delete t;\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```
['Linked List', 'C++']