Skip to content

Commit b2f6c36

Browse files
rotate
1 parent b33b6b2 commit b2f6c36

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

rotate.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#include <algorithm>
2+
#include <iostream>
3+
#include <vector>
4+
5+
// https://stackoverflow.com/questions/11343116/rotating-a-vector-array
6+
7+
int main() {
8+
std::vector<int> v = { 1, 2, 3, 4, 5 };
9+
10+
std::rotate(v.begin(),
11+
v.end() - 1, // this will be the new first element
12+
v.end());
13+
14+
for(int i : v) std::cout << i << " ";
15+
std::cout << std::endl;
16+
17+
return 0;
18+
}

0 commit comments

Comments
 (0)