Last active
December 14, 2025 20:05
-
-
Save vlaleli/7a2c30748019ff321884058c9490f72e to your computer and use it in GitHub Desktop.
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 "VectorTasks.h" | |
| using namespace std; | |
| void printVector(const vector<int>& v) { | |
| for (int x : v) { | |
| cout << x << " "; | |
| } | |
| cout << endl; | |
| } | |
| int main() { | |
| vector<int> data = { 5, 2, 8, 2, 9, 1, 2 }; | |
| cout << "Початковий контейнер: "; | |
| printVector(data); | |
| FindMin findMin; | |
| FindMax findMax; | |
| cout << "Мінімальне значення: " << findMin(data) << endl; | |
| cout << "Максимальне значення: " << findMax(data) << endl; | |
| SortAscending sortAsc; | |
| sortAsc(data); | |
| cout << "Сортування за зростанням: "; | |
| printVector(data); | |
| SortDescending sortDesc; | |
| sortDesc(data); | |
| cout << "Сортування за спаданням: "; | |
| printVector(data); | |
| IncreaseByConstant inc(3); | |
| inc(data); | |
| cout << "Після збільшення на 3: "; | |
| printVector(data); | |
| DecreaseByConstant dec(2); | |
| dec(data); | |
| cout << "Після зменшення на 2: "; | |
| printVector(data); | |
| RemoveEqual removeVal(2); | |
| removeVal(data); | |
| cout << "Після видалення значення 2: "; | |
| printVector(data); | |
| return 0; | |
| } |
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 "VectorTasks.h" | |
| #include <algorithm> | |
| #include <functional> | |
| int FindMin::operator()(const vector<int>& v) const { | |
| return *min_element(v.begin(), v.end()); | |
| } | |
| int FindMax::operator()(const vector<int>& v) const { | |
| return *max_element(v.begin(), v.end()); | |
| } | |
| void SortAscending::operator()(vector<int>& v) const { | |
| sort(v.begin(), v.end()); | |
| } | |
| void SortDescending::operator()(vector<int>& v) const { | |
| sort(v.begin(), v.end(), greater<int>()); | |
| } | |
| IncreaseByConstant::IncreaseByConstant(int v) : value(v) {} | |
| void IncreaseByConstant::operator()(vector<int>& v) const { | |
| for (size_t i = 0; i < v.size(); i++) { | |
| v[i] += value; | |
| } | |
| } | |
| DecreaseByConstant::DecreaseByConstant(int v) : value(v) {} | |
| void DecreaseByConstant::operator()(vector<int>& v) const { | |
| for (size_t i = 0; i < v.size(); i++) { | |
| v[i] -= value; | |
| } | |
| } | |
| RemoveEqual::RemoveEqual(int v) : value(v) {} | |
| void RemoveEqual::operator()(vector<int>& v) const { | |
| v.erase(remove(v.begin(), v.end(), value), v.end()); | |
| } |
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
| #pragma once | |
| #include <vector> | |
| using namespace std; | |
| struct FindMin { | |
| int operator()(const vector<int>& v) const; | |
| }; | |
| struct FindMax { | |
| int operator()(const vector<int>& v) const; | |
| }; | |
| struct SortAscending { | |
| void operator()(vector<int>& v) const; | |
| }; | |
| struct SortDescending { | |
| void operator()(vector<int>& v) const; | |
| }; | |
| struct IncreaseByConstant { | |
| int value; | |
| IncreaseByConstant(int v); | |
| void operator()(vector<int>& v) const; | |
| }; | |
| struct DecreaseByConstant { | |
| int value; | |
| DecreaseByConstant(int v); | |
| void operator()(vector<int>& v) const; | |
| }; | |
| struct RemoveEqual { | |
| int value; | |
| RemoveEqual(int v); | |
| void operator()(vector<int>& v) const; | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment