Making an independent duplicate of a linked list

Making an independent duplicate of a linked list

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?

2 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

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

Retired 12/31/2016

Leave a Comment

Please sign in to add a comment. Not a member? Join today