Hello
I have 2 std::list l1 & l2 (both holdings integers) and I would like to append l2 to the end of l1,
Is there a function that implements that other then itereating l2 and using push_back to l1?
Thanks
avi123
Printable View
Hello
I have 2 std::list l1 & l2 (both holdings integers) and I would like to append l2 to the end of l1,
Is there a function that implements that other then itereating l2 and using push_back to l1?
Thanks
avi123
l1.splice(l1.end(),l2);
note: l2 will be deleted
insert() or splice() depending on what you want ...
Code:// append l1 to l2 (l1 unchanged)
l2.insert(l2.end(),l1.begin(),l1.end());
// append l1 to l2 (elements appended to l2 are removed from l1)
// (general form ... TG gave form that is actually better suited
// for your needs)
l2.splice(l2.end(),l1,l1.begin(),l1.end());
thank you both
I used the insert since I needed to keep the second list
avi123