We can concatenate two Linked List in O(1) time if we know the last element.
So, Is there any way to concatenate two List in C++ using built-in data structures or I have to implement linked list myself then use it?
std::list<int> l1 = create();
std::list<int> l2 = create();
l1.splice(l1.end(), l2);
Note that this empties l2 and moves its elements to l1.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With