C++ without standard library(Only Pointers)
class FrontMiddleBackQueue {\npublic:\n    //Create a Node\n    class Node{\n        public:\n            Node* previous = nullptr;\n            Node* next = nu
```class FrontMiddleBackQueue {\npublic:\n    //Create a Node\n    class Node{\n        public:\n            Node* previous = nullptr;\n            Node* next = nullptr;\n            int val;\n            Node(int v, Node* n, Node* p):val(v), next(n), previous(p){}\n            ~Node(){}\n    };\n    //nodes pointing front, back and middle of the queue\n    Node* front;\n    Node* back;\n    Node* middle;\n    //number of nodes\n    int size;\n    \n    FrontMiddleBackQueue() {\n        //Initialize\n        front = nullptr;\n        back = nullptr;\n        middle = nullptr;\n        size = 0;\n    }\n    \n    void pushFront(int val) {\n        //put back, front andd pointing to the same node\n        if(size == 0){\n            start(val);\n            return;}\n        //new node at the front\n        Node* node = new Node(val, front, nullptr);   \n        front->previous = node;\n        front = node;\n        size++;\n        \n        //if middle if the number of nodes is odd\n        if(size%2!=0)\n            middle = middle->previous;\n    }\n    \n    void pushMiddle(int val){\n        if(size == 0){\n            start(val);\n            return;}\n        //move front in the next node of front\n        if(size == 1){\n            Node* p = new Node(val, back, nullptr);\n            back->previous = p;\n            front = p;\n            size++;\n            return;\n        }\n        \n        //new node at the middle\n        size++;\n        Node* p = new Node(val, middle, middle->previous);\n        p->previous->next = p;\n        p->next->previous = p;\n        \n        if(size%2!=0)\n            middle = p;\n    }\n    \n    void pushBack(int val) {\n        \n        if(size == 0){\n            start(val);\n            return;}\n        // new node at the back\n        size++;\n        Node* node = new Node(val, nullptr, back);\n        back->next = node;\n        back = node;\n        \n        if(size%2==0)\n            middle = middle->next;\n    }\n    //Same analogy but with pop\n    int popFront() {\n        if(size == 0) return -1;\n        int res = front->val;\n        front = front->next;\n        size--;\n        if(size == 0){\n            restart();\n        }\n        if(size%2==0 && size>0)\n            middle = middle->next;\n        return res;\n    }\n    \n    int popMiddle() {\n        if(size == 0) return -1;\n        if(size%2 == 0) {\n            middle = middle->previous;\n            if(middle == front) front = front->next;\n        }\n        int res = middle->val;\n        \n        //if exist\n        if(middle->next)\n        middle->next->previous = middle->previous;\n        //if exist\n        if(middle->previous)\n        middle->previous->next = middle->next;\n        middle = middle->next;\n        size--;\n        if(size == 0){\n            restart();\n        }\n        return res;\n    }\n    \n    int popBack() {\n        if(size == 0) return -1;\n        int res = back->val;\n        back = back->previous;\n        size--;\n        if(size == 0){\n            restart();\n        }\n        if(size%2!=0)\n            middle = middle->previous;\n        return res;\n    }\n    \n    \n    void start(int val){\n        Node* node = new Node(val,nullptr, nullptr);   \n        front = node;\n        back = node;\n        middle = node;\n        size++;\n    }\n    void restart(){\n        front = nullptr;\n        back = nullptr;\n        middle = nullptr;\n    }\n};```
[]