C++ solution using stack  (easy to understand) well commented + explanation
main idea:: a stack is kept for the puspose of storing the the next value of a particular node which has a child node\n\n \n1---2---3---4---5---6--NULL\n       
main idea:: a stack is kept for the puspose of storing the the next value of a particular node which has a child node\n\n ```\n1---2---3---4---5---6--NULL\n         |\n         7---8---9---10--NULL\n             |\n             11--12--NULL\n```\n\nlet me explain with this example ::  \nstep 1)     when 1 is encountered we simply move to the next value since it has so child node.\nstep 2)     similar operation is done in case of node 2\nstep 3)     in this step we use the stack datastructure for storing the next value of 3 .....so 4 gets inserted in the stack\n\t\t\t\tand we  store  7 to the next of 3 so the link list looks like this \n* \t\t\t\t\t\t1--2--3--7\n* \t\t\t\t\t\tstack has : 4\n\t\t\t\t\t\t\nstep 4)\t  we do the same operation in node 7 as in step 1\nstep 5)   same oeration of node 8 as in node \n\t\t\t\tso now the link list looks like ::   1--2--3--7--8--11\n* \t\t\t\tstack contains ::  9    (11 is present at stack.top() )\n \t\t\t\t                            4\nstep 6)  lets come to the end nodes ...... in case of node 12 ::\n\t\t\t   link list would look like \n* \t\t\t   1--2--3--7--8--11--12\n* \t\t\t   stack has : 9\n\t\t\t\t\t*   \t 4 \n\t\t\t\tso now we have to bring the stack.top() in the game and add the address of the stack.top() at the next position of the node 12  and we pop 9 from the stack\n\t\t\t\tso after that operation list looks like this :\n* \t\t\t\t`\t1--2--3--7--8--11--12--9`\nwe do this steps untill we reach a position in which we have stack empty and its a end node( child node and next node **null**) \n\n#            HAPPY CODING \n\n/*\n```\n 1---2---3---4---5---6--NULL\n         |\n         7---8---9---10--NULL\n             |\n             11--12--NULL\n```\n\n*/\n\n\n\n/*\n// Definition for a Node.\nclass Node {\npublic:\n    int val;\n    Node* prev;\n    Node* next;\n    Node* child;\n};\n*/\n\nclass Solution {\npublic:\n    Node* flatten(Node* head) \n    {\n        if(!head)\n            return head;\n        Node* original_head = head;\n        stack< Node* > paser_mal;\n        \n        //paser_mal.push(head->next);\n        \n        while(!paser_mal.empty() or head)   //joto khun na bondho korbo cholbe\n        {\n            //idea : jodi head null hoi tahole stack check hobe ota o khali hole kaaj sesh\n            \n            if(!head and paser_mal.empty())\n                break;\n            if(!head->next and !head->child)  // last er element\n            {\n                if(paser_mal.empty())   //in the example node 6;\n                    break;\n                else \n                {\n                    head->next = paser_mal.top();   // in case of node 10,12  :: 12-> tahole 12->next will be 9\n                    paser_mal.pop();\n                    auto temp = head;\n                    //head->next->prev = head;\n                    if(!head->next)   break;    \n                    head= head->next ; \n                    head->prev = temp;``\n                    head->child = NULL;\n                }\n            }   //last elements cases\n            \n            else if(head->child) //cases with childs\n            {\n                \n                paser_mal.push(head->next);   //stack e next er mal store holo \n                head->next = head->child;\n                head->next->prev = head;\n                head->child = NULL;\n                head = head->next;\n                \n                \n            }\n            \n            else if(!head->child  and head->next)  //child nei stack empty and next element ache\n            {\n                //head->next->prev = head;\n                auto temp = head;\n                head->child = NULL;\n                head= head->next ;    // no child and no element in stack so porer element e jacchi\n                head->prev = temp;\n                \n            }\n    \n            cout<< head->val<<" ";\n        }\n        //head->next = NULL;\n        original_head->prev = NULL;\n        return original_head ;\n    }\n};****\n
['Linked List', 'Doubly-Linked List']