include iostream include vector include string include iterator includ

  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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
#include <iostream>
#include <vector>
#include <string>
#include <iterator>
#include <fstream>
#include <deque>
#include <list>
#include <numeric>
#include <algorithm>
using namespace std;
void Seq1(){
ifstream inFile("Text.txt");
istream_iterator<int> in_iter(inFile);
istream_iterator<int> eof;
vector<int> store(in_iter, eof);
inFile.close();
cout << "Seq1" << endl;
for (int x : store){
cout << x << " ";
}
cout << endl;
}
void Seq2(){ //целые числа с четным кол-вом элементов
deque<int> d;
cout << "Seq 2" << endl;
for (int count=10; count < 20; ++count){
d.push_back(count); // вставляем числа в конец массива
}
for (int index=0; index < d.size(); ++index)
std::cout << d[index] << ' ';
cout << "\n";
std::deque<int>::iterator it = d.begin();
std::advance(it, d.size() / 2);
reverse(d.begin(), it);
reverse(it, d.end());
for (int x : d){
cout << x << " ";
}
cout << endl;
}
void Seq3(){ //целые числа, кол-во которых делится на 3
std::vector<int> d;
cout << "Seq 3" << endl;
for (int count=0; count < 9; ++count)
d.push_back(10 - count); // вставляем числа в конец массива
for (int index=0; index < d.size(); ++index)
std::cout << d[index] << ' ';
std::cout << '\n';
std::vector<int>::iterator it = d.begin();
std::advance(it, d.size() / 3);
std::vector<int>::iterator it2 = d.begin();
std::advance(it2, (d.size() / 3) * 2 );
reverse(it, it2);
reverse(it2, d.end());
for (int x : d){
cout << x << " ";
}
cout << endl;
}
void Seq4(){ // каждый имеет не менее 3 элементов, кол-во нечетное
std::vector<int> v;
cout << "Seq 4" << endl;
for (int count=0; count < 9; ++count)
v.push_back(10 - count);
for (int index=0; index < v.size(); ++index)
std::cout << v[index] << ' ';
cout << "\n";
deque<int> d;
for (int count=9; count < 18; ++count){
d.push_back(count);
}
for (int index=0; index < d.size(); ++index)
std::cout << d[index] << ' ';
cout << "\n";
list<int> l = { 1, 2, 3 };
*(v.begin()) *= 2;
v[v.size() / 2] *= 2;
*(--v.end()) *= 2;
*(d.begin()) *= 2;
d[d.size() / 2] *= 2;
*(--d.end()) *= 2;
*(l.begin()) *= 2;
std::list<int>::iterator it = l.begin();
std::advance(it, l.size() / 2);
*(it) *= 2;
*(--l.end()) *= 2;
for (int x : v){
cout << x << " ";
}
cout << endl;
for (int x : d){
cout << x << " ";
}
cout << endl;
for (int x : l){
cout << x << " ";
}
cout << endl;
}
void Seq5(){ //не менее 2 эл.кол-во эл четное
vector<int> v = { 1, 2, 3, 4, 5, 6, 7, 8 };
deque<int> d = { 5, 6, 7, 8 };
list<int> l = { 1, 2, 3, 4 };
swap(v[v.size() / 2 - 1], v[v.size() / 2]);
swap(d[d.size() / 2 - 1], d[d.size() / 2]);
list<int>::iterator it = l.begin();
advance(it, l.size() / 2 - 1);
swap(*(it), *(it++));
cout << "Seq 5" << endl;
for (int x : v){
cout << x << " ";
}
cout << endl;
for (int x : d){
cout << x << " ";
}
cout << endl;
for (int x : l){
cout << x << " ";
}
cout << endl;
}
void Seq6(){// четное кол-во эл
std::vector<int> v;
cout << "Seq 6" << endl;
for (int count=0; count < 10; ++count)
v.push_back(10 - count);
for (int index=0; index < v.size(); ++index)
std::cout << v[index] << ' ';
cout << "\n";
v.insert(v.begin() + (v.size() / 2), 5, 0);
for (int x : v){
cout << x << " ";
}
cout << endl;
}
void Seq7(){ //нечет кол-во эл. больше 5
deque<int> d;
cout << "Seq 7" << endl;
for (int count=9; count < 18; ++count){
d.push_back(count);
}
for (int index=0; index < d.size(); ++index)
std::cout << d[index] << ' ';
cout << "\n";
d.insert(d.begin(), d.begin() + (d.size() / 2 - 2), d.begin() + (d.size() / 2 + 3));
for (int x : d){
cout << x << " ";
}
cout << endl;
}
void Seq8(){//кол-во эл делится на 3
list<int> l = { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
list<int>::iterator it = l.begin();
advance(it, l.size() / 3);
reverse(l.begin(), it);
l.insert(l.end(), l.begin(), it);
reverse(l.begin(), it);
cout << "Seq 8" << endl;
for (int x : l){
cout << x << " ";
}
cout << endl;
}
void Seq9(){
list<int> l = { 1,2,3,4,5 };
vector<int> v= { 6, 7, 8, 9, 10};
auto i = l.begin();
advance(i, 5);
auto iv = v.begin();
advance(iv, 5);
reverse(v.begin(),iv);
l.insert(i, v.begin(), iv);
cout << "Seq 9" << endl;
for (auto i : l) {
cout << i << " " ;
}
cout << endl;
}
void Seq10(){
deque<int> d= { 1,2,3,4,5,6,7 };
list<int> l = { 9,10,11,12,13,14,15};
auto i = d.end();
advance(i, -5);
reverse(i,d.end());
auto i1 = l.end();
advance(i1, -5);
l.insert(i1, i, d.end());
cout << "Seq 10" << endl;
for (auto i : l) {
cout << i << " ";
}
cout << endl;
}
void Seq11(){// чет кол-во эл
vector<int> v = { 1, 2, 3, 4 };
deque<int> d = { 5, 6, 7, 8 };
deque<int>::iterator d1 = d.begin();
deque<int>::iterator d2 = d.begin();
advance(d2, d.size() / 2);
int s = v.size();
v.insert(v.end(), d1, d2);
reverse(v.begin(), v.end());
vector<int>::iterator v1 = v.end();
vector<int>::iterator v2 = v.end();
advance(v1, -(s / 2));
advance(v2, -(s));
d.insert(d.begin(), v2, v1);
reverse(v.begin(), v.end());
cout << "Seq 11" << endl;
cout << "Vector: ";
for (int x : v){
cout << x << " ";
}
cout << endl;
cout << "Deque: ";
for (int x : d){
cout << x << " ";
}
cout << endl;
}
void Seq12(){
vector<int> v = { 1,2,3,4,5,6,7 };
int k = (v.size() / 2)-1;
vector<int> :: iterator it = v.begin();
advance(it, k);
vector<int> :: iterator it2 = it;
advance(it2, 3);
v.erase(it, it2);
cout << "Seq 12" << endl;
for (int x :v)
cout << x << " ";
cout << endl;
}
void Seq13(){
vector<int> v = {1,2,3,4,5,6,7 };
list<int> l = {1,2,3,4,5,6,7 };
list<int> :: iterator it = l.begin();
advance(it, l.size() / 2);
v.push_back(*it);
cout << "Seq 13" << endl;
for (int x : v)
cout << x << " ";
cout << endl;
l.erase(it);
for (int x : l)
cout << x << " ";
cout << endl;
}
void Seq14(){
deque<int> d = {1,2,3,4,5,6,7,8};
list<int> l = {1,2,3,4,5,6,7};
deque<int> :: iterator it = d.begin();
advance(it, d.size() / 2);
l.insert(l.begin(), d.begin(), it);
d.erase(d.begin(), it);
cout << "Seq 14" << endl;
for (int x : l)
cout << x << " ";
cout << endl;
for ( x : d)
cout << x << " ";
cout << endl;
}
void Seq15(){
list<int> l1 = {1,2,3,4,5,6,7};
list<int> l2 = {1,2,3,4,5,6};
list<int> :: iterator it = l1.begin();
advance(it, l1.size()/2);
l2.splice(l2.end(), l1, it);
cout << "Seq 15" << endl;
for (int x : l1)
cout << x<< " ";
cout << endl;
for (int x : l2)
cout << x << " ";
cout << endl;
}
void Seq16() {
list<int> l1 = { 1, 2, 3, 4, 5 };
list<int> l2 = { 6, 7, 8, 9 };
cout << "Seq 16" << endl;
list<int>::iterator it = l2.begin();
advance(it, l2.size() / 2);
l1.splice(l1.begin(), l2, l2.begin(), it);
cout << "List1: ";
for (int x : l1){
cout << x << " ";
}
cout << endl;
cout << "List2: ";
for (int x : l2){
cout << x << " ";
}
cout << endl;
}
void Seq17() {
list<int> l1 = { 1, 2, 3, 4 };
list<int> l2 = { 6, 7, 8, 9};
cout << "Seq 17" << endl;
list<int>::iterator it1 = l1.begin();
advance(it1, l1.size() / 2);
list<int>::iterator it12 = l1.begin();
list<int>::iterator it2 = l2.begin();
advance(it2, l2.size() / 2);
l1.splice(l1.begin(), l2, it2, l2.end());
l2.splice(l2.end(), l1, it12, it1);
cout << "List1: ";
for (int x : l1){
cout << x << " ";
}
cout << endl;
cout << "List2: ";
for (int x : l2){
cout << x << " ";
}
cout << endl;
}
void Seq18() {
list<int> l1 = { 1, 2, 3, 4, 5, 6, 7, 8 };
cout << "Seq 18" << endl;
bool f = true;
list<int>::iterator it2 = l1.begin();
advance(it2, l1.size() / 2);
for (list<int>::iterator it1 = l1.begin(); it1 != it2;){
if (f){
l1.erase(it1++);
}
else{
++it1;
}
f = !f;
}
cout << "List1: ";
for (int x : l1){
cout << x << " ";
}
cout << endl;
}
int main(){
Seq1();
cout << endl;
Seq2();
cout << endl;
Seq3();
cout << endl;
Seq4();
cout << endl;
Seq5();
cout << endl;
Seq6();
cout << endl;
Seq7();
cout << endl;
Seq8();
cout << endl;
Seq9();
cout << endl;
Seq10();
cout << endl;
Seq11();
cout << endl;
Seq12();
cout << endl;
Seq13();
cout << endl;
Seq14();
cout << endl;
Seq15();
cout << endl;
Seq16();
cout << endl;
Seq17();
cout << endl;
Seq18();
}