Created
June 23, 2016 15:32
-
-
Save fseasy/f33a9d1b075d03a70b66d1989e13d6ff to your computer and use it in GitHub Desktop.
STL中的rotate算法!!牛逼
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
template <class ForwardIterator> | |
void rotateSTL(ForwardIterator first, ForwardIterator middle, | |
ForwardIterator last) | |
{ | |
using std::swap; | |
ForwardIterator next = middle; | |
while(first != next) | |
{ | |
swap(*first++, *next++); | |
if(next == last){ next = middle;} | |
else if(first == middle){ middle = next; } | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment