Return type : An iterator pointing to the element that now contains the value previously pointed by first.
Working: The rotate( ) function takes 3 parameters, 'first' & 'last' and 'start' .Forward iterators to the initial and final positions of the sequence to be rotated left.Forward iterator pointing to the element within the range [first,last)
that is moved to the first position in the range.
Implementation:
#include <iostream> // std::cout
#include <algorithm> // std::rotate
#include <vector> // std::vector
int main () {
std::vector<int> element {1,2,3,4,5,6,7,8,9};
std::rotate(element.begin(),element.begin()+3,element.end());
std::cout << "Element contains:";
for (std::vector<int>::iterator it=element.begin(); it!=element.end(); ++it)
std::cout << ' ' << *it;
std::cout << '\n';
return 0;
}
Output:
Element contains: 4 5 6 7 8 9 1 2 3
Comments