C++ – how to copy one linked list contents to another linked list

clinked list

I have been given list L1, L2. L1 contains 1,2,3 and L2 contains 4,5,6. how do i copy the contents from L2 to the end of L1 so in the end L1 contains 1,2,3,4,5,6. any suggestions?

Best Answer

Not knowing any more about the actual implementation I would say do this:

L1.tail = L2.head

This will link the two list together, You can now throw away the reference to L2.