Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- using namespace std;
- void doSmth(std::vector<int>& v)
- {
- for(auto it = v.begin(); it < v.end(); ++it){
- for(auto it2 = it; (it2 != v.begin()) && (*it2 < *(it2 - 1)); --it2)
- {
- swap(*it2, *(it2 - 1));
- }
- }
- }
- int main()
- {
- vector<int> v = {1, 2, 3, 4, 5};
- doSmth(v);
- for(int i = 0; i < v.size(); i++)
- {
- cout << v[i] << " ";
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement