Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- template <class ForwardIterator>
- void rotate (ForwardIterator first, ForwardIterator middle, ForwardIterator last)
- {
- ForwardIterator next= middle;
- while (first != next)
- {
- swap (*first++, *next++);
- if(next == last)
- next= middle;
- else if (first==middle)
- middle= next;
- }
- }
- T tmp = a; a = b; b = tmp;
- abcdefg : store 'a' in temporary place
- dbcdefg : move s[3] to s[0] (where it belongs in the end, directly)
- dbcgefg : move s[6] to s[3]
- dbcgefc : move s[9%7] to s[6] (wrapping index modulo container size: 9%7 == 2)
- dbfgefc : move s[5] to s[2]
- dbfgebc : move s[1] to s[5] (another wrapping around)
- defgebc : move s[4] to s[1]
- defgabc : move 'a' from temporary place to s[4]
- reverse(first, middle);
- reverse(middle, last);
- reverse(first, last);
Add Comment
Please, Sign In to add comment