Repository navigation
Expand file tree
/
Copy path4_1.cpp
More file actions
74 lines (67 loc) · 2.03 KB
/
Copy path4_1.cpp
File metadata and controls
74 lines (67 loc) · 2.03 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
// Написать класс-функцию (с перегруженным operator()), для выполнения некоторых действий над передаваемым ей контейнером.
// Действия можете придумать любые (например: поменять местами элементы, реверсировать и т. п.), напишите комментарий, что делаете.
// Функция должна быть применима к list, vector, string, хорошо, если и к массивам встроенных типов.
// Количество параметров в функции - по необходимости.
#include <iostream>
#include <algorithm>
#include <vector>
#include <list>
#include <string>
#include <iterator>
using namespace std;
class Rev // Переворачивает массив
{
public:
template <typename Container>
void operator()(Container &obj)
{
reverse(obj.begin(), obj.end());
}
template <typename Container>
void operator()(Container *arr, int n)
{
for (int i = 0, j = n - 1; i < j; i++, j--)
swap(arr[i], arr[j]);
}
};
template <typename Container>
void print(const Container &obj)
{
typename Container::const_iterator i;
for (i = obj.begin(); i != obj.end(); i++)
cout << *i << ' ';
cout << endl;
}
int main()
{
Rev fun;
vector<int> V{1, 2, 3, 4, 5};
cout << "vector" << endl;
print(V);
fun(V);
print(V);
int M[] = {1, 2, 3, 4, 5};
cout << "mass" << endl;
for (int i = 0; i < (sizeof(M) / sizeof(int)); i++)
{
cout << M[i] << " ";
}
cout << endl;
fun(M, sizeof(M) / sizeof(int));
for (int i = 0; i < (sizeof(M) / sizeof(int)); i++)
{
cout << M[i] << " ";
}
cout << endl;
cout << "list" << endl;
list<int> L;
L = {1, 2, 3, 4, 5};
print(L);
fun(L);
print(L);
cout << "string" << endl;
string s = "1245";
print(s);
fun(s);
print(s);
}