-
Notifications
You must be signed in to change notification settings - Fork 0
/
Complete_STL.cpp
138 lines (117 loc) · 2.89 KB
/
Complete_STL.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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
#include <iostream>
#include <list>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <iterator>
using namespace std;
int main() {
list<int> lst = {1, 2, 3, 4, 5};
lst.push_back(6);
lst.push_front(0);
lst.pop_back();
lst.pop_front();
cout << "List elements: ";
for (const auto& elem : lst) {
cout << elem << " ";
}
cout << endl;
deque<int> dq = {1, 2, 3, 4, 5};
dq.push_back(6);
dq.push_front(0);
dq.pop_back();
dq.pop_front();
cout << "Deque elements: ";
for (const auto& elem : dq) {
cout << elem << " ";
}
cout << endl;
queue<int> q;
q.push(1);
q.push(2);
q.push(3);
cout << "Queue front: " << q.front() << endl;
cout << "Queue back: " << q.back() << endl;
q.pop();
cout << "Queue elements after one pop: ";
queue<int> tempQ = q;
while (!tempQ.empty()) {
cout << tempQ.front() << " ";
tempQ.pop();
}
cout << endl;
stack<int> stk;
stk.push(1);
stk.push(2);
stk.push(3);
cout << "Stack top: " << stk.top() << endl;
stk.pop();
cout << "Stack elements after one pop: ";
stack<int> tempS = stk;
while (!tempS.empty()) {
cout << tempS.top() << " ";
tempS.pop();
}
cout << endl;
set<int> st = {3, 1, 4, 1, 5, 9};
st.insert(2);
st.erase(1);
cout << "Set elements: ";
for (const auto& elem : st) {
cout << elem << " ";
}
cout << endl;
map<int, string> mp;
mp[1] = "one";
mp[2] = "two";
mp[3] = "three";
mp.insert({4, "four"});
cout << "Map elements: ";
for (const auto& pair : mp) {
cout << "{" << pair.first << ": " << pair.second << "} ";
}
cout << endl;
unordered_set<int> uset = {5, 1, 2, 3, 2, 4};
uset.insert(6);
uset.erase(3);
cout << "Unordered set elements: ";
for (const auto& elem : uset) {
cout << elem << " ";
}
cout << endl;
unordered_map<string, int> umap;
umap["one"] = 1;
umap["two"] = 2;
umap["three"] = 3;
umap.insert({"four", 4});
cout << "Unordered map elements: ";
for (const auto& pair : umap) {
cout << "{" << pair.first << ": " << pair.second << "} ";
}
cout << endl;
list<int> numbers = {1, 2, 3, 4, 5};
int sum = accumulate(numbers.begin(), numbers.end(), 0);
cout << "Sum of list elements: " << sum << endl;
numbers.push_back(2);
numbers.push_back(3);
numbers.push_back(1);
numbers.sort();
cout << "Sorted list elements: ";
for (const auto& elem : numbers) {
cout << elem << " ";
}
cout << endl;
numbers.unique();
cout << "Unique list elements: ";
for (const auto& elem : numbers) {
cout << elem << " ";
}
cout << endl;
return 0;
}