-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsplice_lists.cpp
More file actions
46 lines (37 loc) · 918 Bytes
/
Copy pathsplice_lists.cpp
File metadata and controls
46 lines (37 loc) · 918 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
39
40
41
42
43
44
45
46
/*
append a list to the end of another list
*/
#include <iostream>
#include <list>
#include <algorithm>
#include <cstdlib>
using std::cout;
int RandInt() { return(std::rand()%100); }
int main()
{
std::srand(97);
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";
n = 8;
std::list<int> bList (n);
std::generate(bList.begin(), bList.end(), RandInt);
bList.sort();
for (auto& e: bList)
cout << e << " ";
cout << "\n";
// move the items in bList to the end of aList, emptying B in so doing
aList.splice(aList.end(), bList);
// print the combined list
for (auto& e: aList)
cout << e << " ";
cout << "\n";
// show that bList is not empty
for (auto& e: bList)
cout << e << " ";
cout << "\n";
}