#include <iostream>
using namespace std;
struct ComparisonOperator
{
int operator()(int a, int b) const
{
return a - b;
}
};
template<typename Callable>
void sort(int *toSort, int arrLen, const Callable & comparator)
{
int tmp;
for (int i = 0; i < arrLen - 1; i++) {
for (int j = i + 1; j < arrLen; j++) {
if (comparator(toSort[i], toSort[j]) > 0) {
tmp = toSort[j];
toSort[j] = toSort[i];
toSort[i] = tmp;
}
}
}
}
int main()
{
int arrLen = 4;
int arr[arrLen] = {5, 2, 8, 1};
ComparisonOperator c;
sort(arr, arrLen, c);
for (int i = 0; i < arrLen; i++) {
std::cout << arr[i];
if (i != arrLen - 1) {
std::cout << ", ";
}
}
return 0;
}