430 扁平化多级双向链表

Node *flatten(Node *head) {
    Node *it = head;
    stack<Node *> stack1;
    while (it) {
        if (it->child) {
             stack1.push(it->next);
                it->next = it->child;
                it->child->prev = it;
                it->child = nullptr;
            } else if (!it->next && !stack1.empty()) {
                it->next = stack1.top();
                if (it->next)
                    it->next->prev = it;
                stack1.pop();
            }
            it = it->next;
        }
        return head;
    }
原文地址:https://www.cnblogs.com/INnoVationv2/p/10261497.html