数据结构之合并链表STL

    xiaoxiao2021-03-25  335

    #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://ju.6miu.com/read-63.html

    最新回复(0)