public ChildNode(int _val, ChildNode _prev, ChildNode _next, ChildNode _child) { val = _val; prev = _prev; next = _next; child = _child; }
public ChildNode Flatten(ChildNode head) { if (head == null) { return(head); } ChildNode current = head; while (current != null) { if (current.child == null) { current = current.next; } else { ChildNode currentChild = current.child; while (currentChild.next != null) { currentChild = currentChild.next; } currentChild.next = current.next; if (current.next != null) { current.next.prev = currentChild; } current.next = current.child; current.child.prev = current; current.child = null; } } return(head); }