-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtut72.cpp
More file actions
54 lines (48 loc) · 1.08 KB
/
tut72.cpp
File metadata and controls
54 lines (48 loc) · 1.08 KB
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
47
48
49
50
51
52
53
54
#include <iostream>
#include <list>
using namespace std;
void display(list<int> &ls)
{
list<int>::iterator it;
for (it = ls.begin(); it != ls.end(); it++)
{
cout << *it << " ";
}
cout << endl;
}
int main()
{
list<int> lst; // List of lenght 0.
lst.push_back(5);
lst.push_back(4);
lst.push_back(3);
lst.push_back(7);
lst.push_back(2);
display(lst);
// lst.sort(); can sort the list
// Removing elements from the list.
// lst.pop_back(); // poped element form the back of the list.
// lst.pop_front(); // poped element form the front of the list.
// lst.remove(3); // Removed the value of the list.
display(lst);
list<int> list2(4); // empty list of lenght 4
list<int>::iterator it;
it = list2.begin();
*it = 90;
it++;
*it = 34;
it++;
*it = 54;
it++;
*it = 23;
it++;
display(list2);
lst.merge(list2);
cout << "List 1 after merging: ";
display(lst);
display(list2);
// Reversing the list
lst.reverse();
display(lst);
return 0;
}