fork download
  1. #include <algorithm>
  2. #include <functional>
  3. #include <iostream>
  4.  
  5. void array_sort(int* arr, int length, bool descending = false)
  6. {
  7. if(descending)
  8. std::sort(arr, arr + length, std::greater<int>());
  9. else
  10. std::sort(arr, arr + length);
  11. }
  12.  
  13. int main()
  14. {
  15. const int size = 5;
  16. int array[size] = {1, 5, 3, 0, -1};
  17. array_sort(array, size);
  18. for(int i = 0; i < size; ++i)
  19. std::cout << array[i] << ' ';
  20. std::cout << std::endl;
  21. array_sort(array, size, true);
  22. for(int i = 0; i < size; ++i)
  23. std::cout << array[i] << ' ';
  24. }
  25.  
Success #stdin #stdout 0s 3344KB
stdin
Standard input is empty
stdout
-1 0 1 3 5 
5 3 1 0 -1