std::rotate vs std::rotate_copy in C++ STL Last Updated : 05 Aug, 2017 Comments Improve Suggest changes Like Article Like Report rotate in STL:It rotates the order of the elements in the range [first, last), in such a way that the element pointed by middle becomes the new first element, i, e, to the left. CPP // Illustrating the use of rotate algorithm #include <bits/stdc++.h> using namespace std; // Driver Program int main() { vector<int> arr; // set some values: 1 2 3 4 5 6 // 7 8 9 for (int i = 1; i < 10; ++i) arr.push_back(i); // Use of rotate rotate(arr.begin(), arr.begin() + 3, arr.end()); // prints the content: cout << "arr contains:"; for (auto i = arr.begin(); i != arr.end(); i++) cout << ' ' << *i; cout << endl; return 0; } Output: arr contains: 4 5 6 7 8 9 1 2 3 rotate_copy:It copies the elements in the range [first, last) to the range beginning at result, but rotates the order of the elements in such a way that the element pointed by middle becomes the first element in the resulting range, i.e, left rotate. CPP // Illustrating the use of rotate_copy #include <bits/stdc++.h> using namespace std; // Driver Program int main() { int arr[] = { 10, 20, 30, 40, 50, 60, 70 }; // Use of rotate_copy vector<int> gfg(7); rotate_copy(arr, arr + 3, arr + 7, gfg.begin()); // prints the content: cout << "gfg contains:"; for (auto i = gfg.begin(); i != gfg.end(); i++) cout << ' ' << *i; cout << endl; return 0; } Output: gfg contains: 40 50 60 70 10 20 30 Comment S Shambhavi Singh 1 Improve S Shambhavi Singh 1 Improve Article Tags : Technical Scripter C++ STL CPP-Library Explore C++ BasicsIntroduction to C++3 min readData Types in C++6 min readVariables in C++4 min readOperators in C++9 min readBasic Input / Output in C++3 min readControl flow statements in Programming15+ min readLoops in C++7 min readFunctions in C++8 min readArrays in C++8 min readCore ConceptsPointers and References in C++5 min readnew and delete Operators in C++ For Dynamic Memory5 min readTemplates in C++8 min readStructures, Unions and Enumerations in C++3 min readException Handling in C++12 min readFile Handling in C++8 min readMultithreading in C++8 min readNamespace in C++5 min readOOP in C++Object Oriented Programming in C++8 min readInheritance in C++6 min readPolymorphism in C++5 min readEncapsulation in C++3 min readAbstraction in C++4 min readStandard Template Library(STL)Standard Template Library (STL) in C++3 min readContainers in C++ STL2 min readIterators in C++ STL10 min readC++ STL Algorithm Library3 min readPractice & ProblemsC++ Interview Questions and Answers1 min readC++ Programming Examples4 min read Like