Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,924 questions

51,857 answers

573 users

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 145 views
1 answer 88 views
2 answers 105 views
1 answer 98 views
1 answer 62 views
1 answer 125 views
1 answer 89 views
89 views asked Nov 28, 2023 by avibootz
...