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 | /* 제너릭 rotate 알고리즘은 지정된 구간을 특정 위치를 중심으로 한 바퀴 돌린다. rotate 알고리즘의 시간 복잡도는 선형적이다. */ #include <iostream> #include <cassert> #include <algorithm> #include <vector> #include <string> using namespace std; int main() { cout<< "Illustrating the generic rotate algorithm." << endl; string s( "Software Engineering " ); vector< char > vector1(s.begin(), s.end()); // "Engineering" 이 맨 앞에 오도록 vector를 rotate 한다. rotate(vector1.begin(), vector1.begin() + 9, vector1.end()); assert (string(vector1.begin(), vector1.end()) == string( "Engineering Software " )); cout<< " --- Ok." << endl; return 0; } |
'STL > 변경 가능 시퀀스 알고리즘' 카테고리의 다른 글
[STL] unique (0) | 2010.05.17 |
---|---|
[STL] search (0) | 2010.05.17 |
[STL] reverse (0) | 2010.05.17 |
[STL] replace (0) | 2010.05.17 |
[STL] remove (0) | 2010.05.17 |