fork download
  1. #include <algorithm>
  2. #include <iostream>
  3. #include <random>
  4. #include <vector>
  5.  
  6. std::vector <int>
  7. createConstVector(int numberOfElements, int increments, std::mt19937& g) {
  8. std::vector<int> v(numberOfElements);
  9. std::generate(v.begin(), v.end(),
  10. [n=0, increments] () mutable { n = n + increments; return n;});
  11. std::shuffle(v.begin(), v.end(), g);
  12. return v;
  13. }
  14.  
  15. auto sortUsingStdSort(const std::vector<int>& vectorToSort) {
  16. auto v = vectorToSort;
  17.  
  18. std::sort(v.begin(), v.end());
  19. return v;
  20. }
  21.  
  22. int main () {
  23. std::random_device rd;
  24. std::mt19937 g(rd());
  25. const std::vector<int> u3 = createConstVector(10, 5, g);
  26. auto sortedVector = sortUsingStdSort(u3);
  27. for (auto v : sortedVector) {
  28. std::cout << " " << v;
  29. }
  30. }
  31.  
Success #stdin #stdout 0s 4272KB
stdin
Standard input is empty
stdout
 5 10 15 20 25 30 35 40 45 50