an example of C++ STL alg
rotate
👍 g++ -std=c++11 rotate.cpp
👍 ./a.out
1 2 3 4 5 6 7
3 4 5 6 7 1 2
golden thumb
lden thumbgo
A B C D E
C D E A B
👍 cat rotate.cpp
#include <iostream>
#include <vector>
#include <list>
using namespace std;
template<typename T>
void prt(T b, T e) {
for(; b != e; ++b)
cout << *b << ' ';
cout << endl;
}
int main() {
vector<int> v{1,2,3,4,5,6,7};
prt(v.begin(), v.end());
rotate(v.begin(),v.begin()+2,v.end());
prt(v.begin(), v.end());
string s{"golden thumb"};
cout << s << endl;
rotate(s.begin(),s.begin()+2,s.end());
cout << s << endl;
list<char> l{'A','B','C','D','E'};
prt(l.begin(), l.end());
auto i = find(l.begin(),l.end(),'C');
rotate(l.begin(),i,l.end());
prt(l.begin(), l.end());
}