简体   繁体   中英

Deep Copy of a circular linked list

Can anyone share their views on how can we do a deep copy a circular linked list in C# (possible explanation of code)?

Basically what I was looking is how do we deep copy the circular single linked list which has a loop and then making a deep copy of it...

We have few algorithms which can identify a loop in a linked list and then figuring out the head of the list. But after that how do we seperate the copy from the whole list..

Why not just keep a reference to the first element you start at, and use that as your head for your copy, and keep moving to 'Next() until you come across that same first element?

Once you do link the last element of your new linked list to the first?

Obviously for each element you do some sort of DeepClone() that is implemented by that class.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM