Created
September 15, 2018 05:17
-
-
Save mochow13/34506bbd05ce16339f2a4508a4bcb0c2 to your computer and use it in GitHub Desktop.
This file contains 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
std::vector<int> collection={1,2,13,5,12,3,4}; | |
// rotating to the left | |
// element at position 3 of the original collection is now the | |
// first element of the rotated collection | |
std::rotate(begin(collection), begin(collection)+3, end(collection)); | |
// rotating to the right | |
// element at position 2 from the end (or at position 4) is now the | |
// last element of the rotated collection | |
std::rotate(rbegin(collection), rbegin(collection)+2, rend(collection)); | |
// Note: in the above code, collection will be changed by both rotation |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment