How to reverse part of a vector between two indexes in C++

1 Answer

0 votes
#include <iostream>
#include <algorithm> 
#include <vector> 

using namespace std;

int main()
{
    vector<int> v{1, 2, 3, 4,5, 6, 7, 8, 9}; 
 
    reverse(v.begin() + 2, v.begin() + 6); 

    for (auto const& v : v) cout << v << " ";
 
    return 0;
}
 
 
 
/*
run:
 
1 2 6 5 4 3 7 8 9 

*/

 



answered Dec 6, 2019 by avibootz

Related questions

...