CPP | Easy To Understand
class FrontMiddleBackQueue {\npublic:\n\n    struct Node{\n         int val;\n         Node next;\n         Node prev;\n         Node(int data){\n             v
class FrontMiddleBackQueue {\npublic:\n\n    struct Node{\n         int val;\n         Node* next;\n         Node* prev;\n         Node(int data){\n             val=data;\n             next=NULL;\n             prev=NULL;\n         }\n    };\n    Node* head=NULL;\n    Node* tail=NULL;\n    FrontMiddleBackQueue() {\n    }\n    \n    // uncomment code to understant working of code\n    void printll(){\n        // Node* s=head;\n        // Node* e=tail;\n        // cout<<"Head -> ";\n        // while(s){\n        //     cout<<s->val<<"->";\n        //     s=s->next;\n        // }\n        // cout<<endl;\n        // cout<<"Tail <- ";\n        // while(e){\n        //     cout<<e->val<<"<-";\n        //     e=e->prev;\n        // }\n        // cout<<endl;\n    }\n    \n    \n    \n    void pushFront(int val){\n        if(head==NULL&&tail==NULL){\n          head=new Node(val); \n          tail=head;\n          // cout<<head->val<<" "<<tail->val<<endl;\n            printll();\n          return ;\n        }\n        Node* nxt=new Node(val);\n        head->prev=nxt;\n        nxt->next=head;\n        head=head->prev;\n                    printll();\n    }\n    \n    void pushMiddle(int val) {\n        if(head==NULL&&tail==NULL){\n          head=new Node(val);\n          tail=head;\n            printll();\n          return;\n        }\n        Node* s=head;\n        Node* e=tail;\n        // cout<<(s->next->val)<<endl;\n        while(s!=e&&s!=e->prev){\n            s=s->next;\n            e=e->prev;\n        }\n        if(head==tail){\n            Node* nn=new Node(val);\n            nn->next=tail;\n            tail->prev=nn;\n            head=nn;\n            return;\n        }\n        // cout<<"push middle"<<endl;\n        // cout<<s->val<<" "<<e->val<<endl;\n        Node* nn=new Node(val);\n        nn->next=e;\n        e->prev->next=nn;\n        nn->prev=e->prev;\n        e->prev=nn;        \n                    printll();\n    }\n    \n    void pushBack(int val) {\n        if(head==NULL&&tail==NULL){\n          head=new Node(val);\n          tail=head;\n                        printll();\n            return ;\n        }\n        Node* nxt=new Node(val);\n        nxt->prev=tail;\n        tail->next=nxt;\n        tail=nxt;\n                    printll();\n    }\n    \n    int popFront() {\n        if(head==NULL&&tail==NULL){\n        return -1;\n        }\n        int x=head->val;\n        if(head->next==NULL){\n            head=NULL;\n            tail=NULL;\n            return x;\n        }\n        head=head->next;\n        head->prev=NULL;\n        printll();\n        return x;\n    }\n    \n    int popMiddle() {\n        if(head==NULL&&tail==NULL){\n        return -1;\n        }\n        Node* s=head;\n        Node* e=tail;\n        while(s!=e&&s!=e->prev){\n            s=s->next;\n            e=e->prev;\n        }\n        int x=s->val;\n        // printll();\n        // cout<<"Check"<<endl;\n        if(head==tail){\n            head=NULL;\n            tail=NULL;\n            return x;\n        }\n        if(head==s&&tail==e){\n        // cout<<"pop mi centre two"<<endl;\n            head=head->next;\n            tail->prev=NULL;\n            printll();\n            return x;\n        }\n        if(head==s){\n            head=head->next;\n            head->prev=NULL;\n            printll();\n            return x;\n        }\n        s->prev->next=s->next;\n        s->next->prev=s->prev;\n        printll();\n        return x;\n    }\n    \n    int popBack(){\n        if(head==NULL&&tail==NULL){\n        return -1;\n        }\n        int x=tail->val;\n        if(tail->prev==NULL){\n            head=NULL;\n            tail=NULL;\n        printll();\n            return x;\n        }\n        tail=tail->prev;\n        tail->next=NULL;\n        printll();\n        return x;\n        \n    }\n};\n
['Linked List', 'C', 'C++']