C++ Simple list traversal without using stack/queue/DFS
\nclass Solution {\npublic:\n    Node* flatten(Node* head) {\n        Node* lead=head;\n        Node* ptr=NULL;      \n        Node* beta=NULL;   // beta is chi
```\nclass Solution {\npublic:\n    Node* flatten(Node* head) {\n        Node* lead=head;\n        Node* ptr=NULL;      \n        Node* beta=NULL;   // beta is child node\n        while(head){\n            if(head->child){\n                ptr=head->next;\n                beta=head->child;\n                head->child=NULL;\n                head->next=beta;\n                beta->prev=head;\n                while(beta->next){\n                    beta=beta->next;\n                }\n                if(ptr)\n                    ptr->prev=beta;\n                beta->next=ptr;\n            }\n            head=head->next;\n        }\n        return lead;\n    }\n};\n```
['C']