[c++] Stack solution with explanation
simple explanation: as we go along our list, if we reach a node where its child is not a null pointer then we push the next node on to our stack and set the nex
simple explanation: as we go along our list, if we reach a node where its child is not a null pointer then we push the next node on to our stack and set the next node to the child node. Of course we also have to set the child to a null pointer, and set our next nodes previous node to the current node.\n\nWe repeat this process untill we eventually reach an end.\nfrom there we start unloading the stack, this cycle repeats eventually flattening out the list.\n\n\n```\nclass Solution {\npublic:\n    Node* flatten(Node* head) {\n     Node * dummyHead = head;   \n     stack <Node*> stack;   \n     while(head || !stack.empty())\n     {\n       if(head && head -> child)\n       { \n        if(head -> next) stack.push(head -> next);   \n             \n        head -> next = head -> child;  \n        head -> next -> prev = head;   \n        head -> child = nullptr;   \n       }\n       else if(!head -> next && !stack.empty())\n       {                 \n        head -> next= stack.top(); \n        head -> next -> prev = head; \n        stack.pop();\n\t   }\n       if(head) head = head -> next;  \n     }   \n        return dummyHead;\n    }\n};\n```
['Stack', 'C', 'C++']