#include <algorithm>
#include <functional>
#include <iostream>
void array_sort(int* arr, int length, bool descending = false)
{
if(descending)
std::sort(arr, arr + length, std::greater<int>());
else
std::sort(arr, arr + length);
}
int main()
{
const int size = 5;
int array[size] = {1, 5, 3, 0, -1};
array_sort(array, size);
for(int i = 0; i < size; ++i)
std::cout << array[i] << ' ';
std::cout << std::endl;
array_sort(array, size, true);
for(int i = 0; i < size; ++i)
std::cout << array[i] << ' ';
}
I2luY2x1ZGUgPGFsZ29yaXRobT4KI2luY2x1ZGUgPGZ1bmN0aW9uYWw+CiNpbmNsdWRlIDxpb3N0cmVhbT4KCnZvaWQgYXJyYXlfc29ydChpbnQqIGFyciwgaW50IGxlbmd0aCwgYm9vbCBkZXNjZW5kaW5nID0gZmFsc2UpCnsKICAgIGlmKGRlc2NlbmRpbmcpCiAgICAgICAgc3RkOjpzb3J0KGFyciwgYXJyICsgbGVuZ3RoLCBzdGQ6OmdyZWF0ZXI8aW50PigpKTsKICAgIGVsc2UKICAgICAgICBzdGQ6OnNvcnQoYXJyLCBhcnIgKyBsZW5ndGgpOwp9CgppbnQgbWFpbigpCnsKICAgIGNvbnN0IGludCBzaXplID0gNTsKICAgIGludCBhcnJheVtzaXplXSA9IHsxLCA1LCAzLCAwLCAtMX07CiAgICBhcnJheV9zb3J0KGFycmF5LCBzaXplKTsKICAgIGZvcihpbnQgaSA9IDA7IGkgPCBzaXplOyArK2kpCiAgICAgICAgc3RkOjpjb3V0IDw8IGFycmF5W2ldIDw8ICcgJzsKICAgIHN0ZDo6Y291dCA8PCBzdGQ6OmVuZGw7CiAgICBhcnJheV9zb3J0KGFycmF5LCBzaXplLCB0cnVlKTsKICAgIGZvcihpbnQgaSA9IDA7IGkgPCBzaXplOyArK2kpCiAgICAgICAgc3RkOjpjb3V0IDw8IGFycmF5W2ldIDw8ICcgJzsKfQo=