JavaScript Iterative Solution| Easy- with example walkthrough
\n /*\n Time: O(n) || Space: O(n)\n Please upvote if you find implementation with example useful, \n i\'ll try to implement examples in my future posts as well 
```\n /*\n Time: O(n) || Space: O(n)\n Please upvote if you find implementation with example useful, \n i\'ll try to implement examples in my future posts as well :) \n*/\nvar flatten = function(head) {\n    let temp = head;\n    let stack = [];\n    \n    while (head) {\n        if (head.child) {\n            if (head.next) {\n                stack.push(head.next);\n            }\n            head.next = head.child;\n            head.next.prev = head;\n            head.child = null;\n        } else if (!head.next && stack.length > 0) { //if head.next is null but there are still nodes in stack\n            head.next = stack.pop(); //head.next will point to the popped value from stack\n            head.next.prev = head;\n        }\n        head = head.next; //so the iteration continues to the next node and then next node\n    }\n    return temp;\n};\n\n/*\n\n 1---2---3---4---5---6--NULL\n         |\n         7---8---9---10--NULL\n             |\n             11--12--NULL\n\nStep1:\nhead is 3\nstack = [---4---5---6--NULL]\n             \n 1---2---3\n         |\n         7---8---9---10--NULL\n             |\n             11--12--NULL\n             \n\nStep2:\nstack = [---4---5---6--NULL]\n             \n 1---2---3--7---8---9---10--NULL\n                |\n                11--12--NULL\n                          \n\nStep3:\nstack = [---4---5---6--NULL, ---9---10--NULL]\n             \n 1---2---3--7---8---11--12--NULL      \n \nStep4:\nstack.pop() and append it to the next of last node in linked list, it will look like this\nstack = [---4---5---6--NULL]\n             \n 1---2---3--7---8---11--12---9---10--NULL  \n \n\nStep5:\nstack.pop() and append it to the next of last node in linked list, it will look like this\nstack = []\n             \n 1---2---3--7---8---11--12---9---10----4---5---6--NULL\n \n \n Step6:\n return the result = 1---2---3--7---8---11--12---9---10----4---5---6--NULL\n \n */\n```\n
['Stack', 'Depth-First Search', 'Iterator', 'JavaScript']