-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmerge_lists.cpp
More file actions
38 lines (31 loc) · 790 Bytes
/
Copy pathmerge_lists.cpp
File metadata and controls
38 lines (31 loc) · 790 Bytes
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
#include <iostream>
#include <list>
#include <algorithm>
#include <cstdlib>
using std::cout;
int RandInt() { return(std::rand()%100); }
int main()
{
std::srand(97);
// create a list of randomly generated ints and print it
int n = 15;
std::list<int> aList (n);
std::generate(aList.begin(), aList.end(), RandInt);
aList.sort();
for (auto& e: aList)
cout << e << " ";
cout << "\n";
// create and print another list
n = 8;
std::list<int> bList (n);
std::generate(bList.begin(), bList.end(), RandInt);
bList.sort();
for (auto& e: bList)
cout << e << " ";
cout << "\n";
// merge the two lists and print the result
aList.merge(bList);
for (auto& e: aList)
cout << e << " ";
cout << "\n";
}