Node *flatten(Node *node) {
if (!node)
return NULL;
Node *head = node;
Node *next = node->next;
node->next = NULL;
if (node->down)
node->next = flatten(node->down);
while (node->next != NULL)
node = node->next;
node->next = flatten(next);
return head;
}On Wed, Feb 16, 2011 at 8:38 PM, bittu <[email protected]> wrote: > Given a linked list structure where every node represents a linked > list and contains two pointers of its type: > (i) pointer to next node in the main list. > (ii) pointer to a linked list where this node is head. > > Write a C function to flatten the list into a single linked list. > > Eg. > > If the given linked list is > 1 -- 5 -- 7 -- 10 > | | | > 2 6 8 > | | > 3 9 > | > 4 > > then convert it to > 1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - 9 -10 > > Thanks & Regards > Shashank Mani > > -- > You received this message because you are subscribed to the Google Groups > "Algorithm Geeks" group. > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]. > For more options, visit this group at > http://groups.google.com/group/algogeeks?hl=en. > > -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
