-
Notifications
You must be signed in to change notification settings - Fork 0
/
sort_list.cc
42 lines (42 loc) · 813 Bytes
/
sort_list.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include<list>
#include<iostream>
using namespace std;
int main() {
int n;
cin >> n;
list<int> l1, l2, l3;
int tmp;
for (int i = 0; i< n; ++i) {
cin >> tmp;
l1.push_back(tmp);
}
cin >> n;
for (int i = 0; i< n; ++i) {
cin >> tmp;
l2.push_back(tmp);
}
while (!l1.empty() || !l2.empty()) {
if (!l1.empty() && !l2.empty()) {
if (l1.front() < l2.front()) {
l3.push_back(l1.front());
l1.pop_front();
} else {
l3.push_back(l2.front());
l2.pop_front();
}
continue;
}
if (!l1.empty()) {
l3.push_back(l1.front());
l1.pop_front();
continue;
}
if (!l2.empty()) {
l3.push_back(l2.front());
l2.pop_front();
}
}
for (int l : l3) cout << l << " ";
cout << "\n";
return 0;
}