Skip to content

Instantly share code, notes, and snippets.

@fseasy
Created June 23, 2016 15:32
Show Gist options
  • Save fseasy/f33a9d1b075d03a70b66d1989e13d6ff to your computer and use it in GitHub Desktop.
Save fseasy/f33a9d1b075d03a70b66d1989e13d6ff to your computer and use it in GitHub Desktop.
STL中的rotate算法!!牛逼
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