I have some C code, where in there are two linked lists(say A and B) and A is inserted at a particular position into B and A still has elements.
How do I simulate the same behavior effectively using the C++ STL? If I try splice, it makes the second one empty.
Thanks,
Gokul.
You need to copy the elements. Consider something like this:
If you want the same nodes shared by two lists, this is simply not supported by
std::list(STL containers always have exclusive ownership). You can avoid duplicating the elements by storing pointers in the list, or by usingboost::ptr_list, which internally stores pointers but offers a nicer API.