Re: List Flattening
When a child list is appended to the top level, it is attached to the end of the top level. Hence, as processing continues along the top level, nodes that had been only on the second level are reached on the top level, allowing third-level children (and so on) to be appended to the end of the top level also.
I hope this remark helps.
Regards,
Wayne
p.s. Note that, in the original problem statement, each non-NULL child pointer pointed to a *separate* doubly-liked list. Without this assumption, flattening would do strange things, such as introducing cycles into the list-with-children. That's why my original solution to this problem would have made undoing this operation with an unflattening operation impossible. I carefully reset each child pointer to NULL, making a single top-level list following the original stricture that any non-NULL child pointer (there wouldn't be any anymore) would point to a *separate* doubly-linked list. My flattening operation could be called again on the result of my flattening operation and result in no change. Be aware that after the book's flattening operation is called on a list obeying the original requirements, calling it on the result would violate those original requirements and very likely result in non-termination (or some other bad outcome).
|