There is a special linked list where each node have two pointers, one pointer for next node and one pointer for randomly chosen node. Create a deep copy of this list.
Anoniem
Here's an answer (in C#): static LinkedList Copy(LinkedList source) { Dictionary map = new Dictionary(source.Count * 2); LinkedList copy = new LinkedList(); foreach(Node x in source) { var clone = (Node)x.Clone(); copy.AddLast(clone); map.Add (x, clone); } foreach(Node x in copy) { x.RandomLink = map[x.RandomLink]; } return copy; }