1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
|
#include <iostream>
#include <algorithm>
#include <vector>
using std::cout;
using std::endl;
int main () {
const int SIZE(9);
// Notice how the rotations will result in 1, 2, 3, 4, 5, 6, 7, 8, 9
// create an array of 9 elements and rotate the entire array.
int myArray[SIZE] = { 7, 8, 9, 1, 2, 3, 4, 5, 6, };
std::rotate(myArray, myArray + 3, myArray + SIZE);
// create an array of 9 elements and rotate the first 6 elements.
int myOtherArray[SIZE] = { 2, 3, 4, 5, 6, 1, 7, 8, 9 };
std::rotate(myOtherArray, myOtherArray + 5, myOtherArray + 6);
// print out content:
cout << "myArray contains:";
for (int i = 0; i < SIZE; ++i)
cout << " " << myArray[i];
cout << endl;
cout << "myOtherArray contains:";
for (int i = 0; i < SIZE; ++i)
cout << " " << myOtherArray[i];
cout << endl;
return 0;
}
|