数据结构之合并链表STL

#include <iostream>
#include <list>

using namespace std;

int main()
{
	int n, m;
	while (cin >> n >> m) {
		list<int> l1, l2;
        int num;
		for (int i = 0; i < n; i++) {
			cin >> num;
			l1.push_back(num);
		}

		for (int i = 0; i < m; i++) {
			cin >> num;
			l2.push_back(num);
		}
		l1.merge(l2);
		if (l1.size() == 0) {
			cout << "NULL" << endl;
		} else {
			bool first = true;
			for (list<int>::const_iterator it = l1.begin(); it != l1.end(); it++) {
				if (first)first = false;
				else cout << " ";
				cout << *it ;
			}
			cout << endl;
		}
	}
	return 0;
}

原文地址:https://www.cnblogs.com/jasonhaven/p/7355031.html