Copy a linked list

Posted by emkrish on Stack Overflow See other posts from Stack Overflow or by emkrish
Published on 2010-02-11T05:50:44Z Indexed on 2010/03/30 1:33 UTC
Read the original article Hit count: 457

typedef struct Node
{
  int data;
  Node *next;
  Node *other;
};

Node *pHead;

pHead is a singly linked list. The next field points to the next element in the list. The other field may point to any other element (could be one of the previous nodes or one of the nodes ahead) in the list or NULL.

How does one write a copy function that duplicates the linked list and its connectivity? None of the elements (next and other) in the new list should point to any element in the old list.

© Stack Overflow or respective owner

Related posts about linked-list

Related posts about c