fork download
  1. #include <iostream>
  2. #include <algorithm>
  3. #include <vector>
  4.  
  5. template<class Iter>
  6. void simple_sort(Iter first, Iter last)
  7. {
  8. int zeros = 0;
  9. for (auto it = first; it != last; ++it)
  10. if (*it == 0) ++zeros;
  11.  
  12. std::fill_n(first, zeros, 0);
  13. std::fill_n(first + zeros, last - first - zeros, 1);
  14. }
  15.  
  16. int main()
  17. {
  18. std::vector<int> v = { 0, 0, 1, 0, 1, 0, 0, 0, 1, 1, 0 };
  19. simple_sort(v.begin(), v.end());
  20.  
  21. for (const auto &i : v)
  22. std::cout << i << " ";
  23. std::cout << std::endl;
  24. }
  25.  
Success #stdin #stdout 0s 3468KB
stdin
Standard input is empty
stdout
0 0 0 0 0 0 0 1 1 1 1