文章
49
粉丝
90
获赞
9
访问
27.3k
#include<iostream>
#include<list>
using namespace std;
void my_merge(list<int>& l1, list<int> l2)
{
if (l1.empty())
{
l1 = l2;
}
else if (l2.empty())
{
;
}
else
{
auto it1 = l1.begin();
auto it2 = l2.begin();
while (it1 != l1.end() && it2 != l2.end())
{
if (*it1 > *it2)
{
l1.insert(it1, *it2);
it2++;
}
else
{
it1++;
}
}
while (it2 != l2.end())
{
l1.emplace_back(*it2);
it2++;
}
}
}
int main()
{
list<int> l1;
list<int> l2;
int a, b, t;
cin >> a;
for (int i = 0; i < a; i++)
{
cin >> t;
l1.emplace_back(t);
}
cin >> b;
for (int i = 0; i < b; i++)
{
cin >> t;
l2.emplace_back(t);
}
my_merge(l1, l2);
for (auto t : l1)
{
cout << t << " ";
}
cout << endl;
return 0;
}
登录后发布评论
暂无评论,来抢沙发