Created
January 13, 2026 03:33
-
-
Save ExtremeFine21/abeb6bebe2e94f4e0f99cc8214ecd7e2 to your computer and use it in GitHub Desktop.
Лабораторная работа 27
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #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