Rotate a sequence in vector
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
vector<int> vectorObject;
vector<int>::iterator p;
int i;
for(i = 0; i <10; i++)
vectorObject.push_back(i);
cout << "Original ordering: ";
for(p=vectorObject.begin(); p<vectorObject.end(); p++)
cout << *p << " ";
cout << endl;
rotate(vectorObject.begin(), vectorObject.begin()+1, vectorObject.end()); // rotate left one position
cout << "Order after left rotate: ";
for(p=vectorObject.begin(); p<vectorObject.end(); p++)
cout << *p << " ";
cout << endl;
return 0;
}
Related examples in the same category