0 votes
in Other by
How to copy linked list with arbitrary pointer?

1 Answer

0 votes
by

For example, you have a linked list, and you want to copy it. But you don't have a pointer to the first element, so you can't use the standard library function memcpy(). How do you do it?

The solution is as follows:

Traverse the given linked list and copy the data of each node to a new location.

Update the pointer in the original list to point to the next node.

Recursively copy the new list to the same new location.

...