Skip to content

Instantly share code, notes, and snippets.

@ExtremeFine21
Created January 13, 2026 03:33
Show Gist options
  • Select an option

  • Save ExtremeFine21/abeb6bebe2e94f4e0f99cc8214ecd7e2 to your computer and use it in GitHub Desktop.

Select an option

Save ExtremeFine21/abeb6bebe2e94f4e0f99cc8214ecd7e2 to your computer and use it in GitHub Desktop.
Лабораторная работа 27
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
class AddConst {
int k;
public:
AddConst(int value) : k(value) {}
void operator()(int& x) { x += k; }
};
class SubConst {
int k;
public:
SubConst(int value) : k(value) {}
void operator()(int& x) { x -= k; }
};
class DescSort {
public:
bool operator()(int a, int b) { return a > b; }
};
int main() {
vector<int> v = {5, 2, 8, 2, 10, 3};
cout << *min_element(v.begin(), v.end()) << endl;
cout << *max_element(v.begin(), v.end()) << endl;
sort(v.begin(), v.end());
for (int x : v) cout << x << " ";
cout << endl;
sort(v.begin(), v.end(), DescSort());
for (int x : v) cout << x << " ";
cout << endl;
for_each(v.begin(), v.end(), AddConst(3));
for (int x : v) cout << x << " ";
cout << endl;
for_each(v.begin(), v.end(), SubConst(2));
for (int x : v) cout << x << " ";
cout << endl;
v.erase(remove(v.begin(), v.end(), 5), v.end());
for (int x : v) cout << x << " ";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment