fork download
  1. #include <iostream>
  2. #include <array>
  3. #include <algorithm>
  4. #include <random>
  5.  
  6. template < typename T, unsigned N >
  7. void print_table( const std::array<T, N> & array )
  8. {
  9. std::cout << "array{";
  10. for ( auto i : array )
  11. std::cout << i << ", ";
  12. std::cout << "}" << std::endl;
  13. }
  14.  
  15. int main()
  16. {
  17. std::array<int, 20> numbers;
  18.  
  19. std::random_device rd;
  20. std::mt19937 mt(rd());
  21. std::uniform_int_distribution<int> dist(1,20);
  22.  
  23. std::generate(std::begin(numbers), std::end(numbers), [&](){ return dist(mt);});
  24.  
  25. print_table(numbers);
  26. std::stable_sort(std::begin(numbers), std::end(numbers));
  27. print_table(numbers);
  28.  
  29. return 0;
  30. }
Success #stdin #stdout 0s 3420KB
stdin
Standard input is empty
stdout
array{19, 5, 3, 6, 1, 19, 8, 6, 15, 9, 10, 17, 2, 6, 15, 6, 8, 17, 9, 6, }
array{1, 2, 3, 5, 6, 6, 6, 6, 6, 8, 8, 9, 9, 10, 15, 15, 17, 17, 19, 19, }