October 1999
Beginner
304 pages
7h 11m
English
rotate() is passed three iterators: first, middle, and last. It exhanges the two ranges marked by the iterators first, middle-1 and middle, last-1. For example, given the following C-style character string "boohiss!!",
char ch[] = "boohiss!!";
To change it to "hissboo!!", the call to rotate() looks like this:
rotate( ch, ch+3, ch+7 );
Here is another example:
#include <algorithm>
int ia[] = { 1, 3, 5, 7, 9, 0, 2, 4, 6, 8, 10 };
vector<int> vec( ia, ia+11 ), vec2(11); In this first invocation, we exchange the last six elements, beginning with 0, with the first five elements, beginning with 1:
// rotate on middle element(0) : 0 2 4 6 8 10 1 3 5 7 9 rotate( ia, ia+5, ia+11 );
In this second invocation, we exchange ...
Read now
Unlock full access