Advertisement
Guest User

Untitled

a guest
Oct 20th, 2019
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.46 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. using namespace std;
  4.  
  5. void doSmth(std::vector<int>& v)
  6. {
  7. for(auto it = v.begin(); it < v.end(); ++it){
  8. for(auto it2 = it; (it2 != v.begin()) && (*it2 < *(it2 - 1)); --it2)
  9. {
  10. swap(*it2, *(it2 - 1));
  11. }
  12. }
  13. }
  14.  
  15. int main()
  16. {
  17. vector<int> v = {1, 2, 3, 4, 5};
  18. doSmth(v);
  19. for(int i = 0; i < v.size(); i++)
  20. {
  21. cout << v[i] << " ";
  22. }
  23. return 0;
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement