using stack simple approch
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```\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        stack<Node*>st;\n        Node *p = head;\n        Node *f = NULL;\n        while(p!=NULL or !st.empty()){\n            if(p==NULL){\n                f->next = st.top();\n                st.top()->prev = f;\n                st.pop();\n                p = f->next;\n                continue;\n            }\n            if(p->child!=NULL){\n                f = p;\n                if(p->next)st.push(p->next);\n                p->next = p->child;\n                p->child->prev = p;\n                p->child = NULL;\n                p = p->next;\n            }else{\n                f = p;\n                p = p->next;\n            }\n        }\n        return head;\n    }\n};\n```
['C++']