How to merge two lists into the first list in C++

1 Answer

0 votes
#include <iostream>  
#include <list> 

using std::list;
using std::cout;

void printList(const list<int>& lst)
{
	for (auto elem : lst) {
		cout << elem << ' ';
	}
	cout << std::endl;
}

int main()
{
	list<int> list1{ 1, 2, 3, 4, 5 }, list2{ 77, 88, 99 };

	list1.merge(list2);

	printList(list1);

	return 0;
}

/*
run:

1 2 3 4 5 77 88 99

*/

 



answered Jan 6, 2018 by avibootz
edited Jan 7, 2018 by avibootz

Related questions

1 answer 212 views
1 answer 181 views
1 answer 166 views
166 views asked Apr 21, 2018 by avibootz
2 answers 239 views
...