-
Notifications
You must be signed in to change notification settings - Fork 1
/
STL_Sequence_container_List_1.cpp
105 lines (87 loc) · 3.48 KB
/
STL_Sequence_container_List_1.cpp
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
/*
CPP program to show the implementation of List
List containers are implemented as doubly-linked lists; Doubly linked lists can store each of the elements they contain in different and unrelated storage locations.
(constructor) Construct list (public member function)
(destructor) List destructor (public member function)
operator= Assign content (public member function)
Iterators:
begin Return iterator to beginning (public member function)
end Return iterator to end (public member function)
rbegin Return reverse iterator to reverse beginning (public member function)
rend Return reverse iterator to reverse end (public member function)
cbegin Return const_iterator to beginning (public member function)
cend Return const_iterator to end (public member function)
crbegin Return const_reverse_iterator to reverse beginning (public member function)
crend Return const_reverse_iterator to reverse end (public member function)
Capacity:
empty Test whether container is empty (public member function)
size Return size (public member function)
max_size Return maximum size (public member function)
Element access:
front Access first element (public member function)
back Access last element (public member function)
Modifiers:
assign Assign new content to container (public member function)
emplace_front Construct and insert element at beginning (public member function)
push_front Insert element at beginning (public member function)
pop_front Delete first element (public member function)
emplace_back Construct and insert element at the end (public member function)
push_back Add element at the end (public member function)
pop_back Delete last element (public member function)
emplace Construct and insert element (public member function)
insert Insert elements (public member function)
erase Erase elements (public member function)
swap Swap content (public member function)
resize Change size (public member function)
clear Clear content (public member function)
Operations:
splice Transfer elements from list to list (public member function)
remove Remove elements with specific value (public member function)
remove_if Remove elements fulfilling condition (public member function template)
unique Remove duplicate values (public member function)
merge Merge sorted lists (public member function)
sort Sort elements in container (public member function)
reverse Reverse the order of elements (public member function)
Observers:
get_allocator Get allocator (public member function)
*/
#include <iostream>
#include <iterator>
#include <list>
#include <algorithm>
using namespace std;
// function for printing the elements in a list
void showlist(list<int> g)
{
list<int>::iterator it;
for (it = g.begin(); it != g.end(); ++it)
cout << '\t' << *it;
cout << '\n';
}
int main()
{
list<int> gqlist1, gqlist2;
for (int i = 0; i < 10; ++i) {
gqlist1.push_back(i * 2);
gqlist2.push_front(i * 3);
}
cout << "\nList 1 (gqlist1) is : ";
showlist(gqlist1);
cout << "\nList 2 (gqlist2) is : ";
showlist(gqlist2);
cout << "\ngqlist1.front() : " << gqlist1.front();
cout << "\ngqlist1.back() : " << gqlist1.back();
cout << "\ngqlist1.pop_front() : ";
gqlist1.pop_front();
showlist(gqlist1);
cout << "\ngqlist2.pop_back() : ";
gqlist2.pop_back();
showlist(gqlist2);
cout << "\ngqlist1.reverse() : ";
gqlist1.reverse();
showlist(gqlist1);
cout << "\ngqlist2.sort(): ";
gqlist2.sort();
showlist(gqlist2);
return 0;
}