How to circularly rotate a vector to left by N places in C++

1 Answer

0 votes
#include <vector>
#include <iostream>
#include <algorithm>
  
int main()
{
    std::vector<int> vec {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
    int N = 3;

    std::rotate(vec.begin(), vec.begin() + N, vec.end());
    
    for (auto n : vec) {
        std::cout << n << ' ';
    }
}
  
  
  
  
/*
run:
  
3 4 5 6 7 8 9 0 1 2 
  
*/

 



answered Nov 28, 2023 by avibootz

Related questions

2 answers 108 views
1 answer 74 views
2 answers 91 views
1 answer 83 views
1 answer 9 views
1 answer 112 views
1 answer 78 views
78 views asked Nov 28, 2023 by avibootz
...