Skip to content

Instantly share code, notes, and snippets.

@XoLinA
Created December 24, 2025 11:18
Show Gist options
  • Select an option

  • Save XoLinA/25abec4aa6867f5156d77f9be62b9aa0 to your computer and use it in GitHub Desktop.

Select an option

Save XoLinA/25abec4aa6867f5156d77f9be62b9aa0 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
class FindMin
{
public:
int operator()(const vector <int> & v)
{
return *min_element(v.begin(), v.end());
}
};
class FindMax
{
public:
int operator()(const vector <int> & v)
{
return *max_element(v.begin(), v.end());
}
};
class SortAsc
{
public:
void operator()(vector <int> & v)
{
sort(v.begin(), v.end());
}
};
class SortDesc
{
public:
void operator()(vector <int> & v)
{
sort(v.begin(), v.end(), greater <int> ());
}
};
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 RemoveValue
{
int value;
public:
RemoveValue(int v) : value(v) {}
void operator()(vector <int> & vec)
{
vec.erase(
remove(vec.begin(), vec.end(), value),
vec.end()
);
}
};
void Print(const vector <int> & v)
{
for (int i = 0; i < v.size(); i++)
cout << v[i] << " ";
cout << endl;
}
int main()
{
vector<int> v = { 5, 2, 9, 2, 1, 7 };
Print(v);
FindMin fmin;
FindMax fmax;
cout << "Min: " << fmin(v) << endl;
cout << "Max: " << fmax(v) << endl;
SortAsc asc;
asc(v);
cout << "Asc: ";
Print(v);
SortDesc desc;
desc(v);
cout << "Desk: ";
Print(v);
for_each(v.begin(), v.end(), AddConst(3));
cout << "+3: ";
Print(v);
for_each(v.begin(), v.end(), SubConst(2));
cout << "-2: ";
Print(v);
RemoveValue rem(2);
rem(v);
cout << "Del all 2: ";
Print(v);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment