Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

copy link list

Status
Not open for further replies.

DotNetGnat

Programmer
Mar 10, 2005
5,548
IN
Guys,

What is the best approach to copy a very large doubly linked list(lets say having million nodes) to another list.

Thanks

-DNG
 
The best way is to use a std::list class and let it do all the work for you.
 
If the original list isn't being used any more, consider just swapping the internal data of the two lists. This avoids a copy entirely.
 
Are you writing the list or using the STL list class?

If writing your own, and you don't need the original, like uilj said, just attach the one list to the other. If you're writing the copy constructor or an insert for one list into another, you have to loop through each element and declare new nodes as you go.

[plug=shameless]
[/plug]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top