Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
28632 Discussions

Making an independent duplicate of a linked list

Jacob_Williams
New Contributor II
231 Views

I was wondering about something: does anyone know of a slick way to make a copy of a linked list so that the pointers in the new list don't point back to the original list?  Basically, to clone it so that the two are complete independent, but contain the same data.  allocate(new,source=old) doesn't work because the new pointers point the same locations as the old ones.  I suspect such a thing isn't possible, without manually traversing the structure, but was wondering if anyone had any ideas.  I think the Fortran 2008 "Allocatable components of recursive type" feature might make something like this easier?

0 Kudos
1 Reply
Steven_L_Intel1
Employee
231 Views

No, that would not make it easier. You have to traverse the list. You really can't use allocatables for list links.

0 Kudos
Reply