관리 메뉴

Kim's Programming

Algorithm - rotate_copy() 본문

STL - Algorithm/Algorithm - Modifying

Algorithm - rotate_copy()

Programmer. 2017. 7. 13. 14:20

원형)


1
2
3
template <class ForwardIterator, class OutputIterator>
  OutputIterator rotate_copy (ForwardIterator first, ForwardIterator middle,
                              ForwardIterator last, OutputIterator result);
cs



의미)


.[Iterator first, Iterator last)사이에 있는 데이터들에 대해서 Iterator middle이 가리키는 값이 첫 값이 되도록 하여 Iterator result가 가리키는 위치부터 복사합니다.



소스)


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include<iostream>
#include<algorithm>
#include<vector>
 
void Print(const std::vector<int>& target)
{
    for (std::vector<int>::const_iterator iterPos = target.begin(); iterPos != target.cend(); iterPos++)
        std::cout << *iterPos << ' ';
    std::cout << std::endl;
}
 
void main()
{
    std::vector<int> vector = { 1,3,5,4,3,2,6,7,9,11 };
    std::vector<int> vectorCopy(10);
    std::cout << "Vector--->";Print(vector);
    std::cout << "VectorCopy--->";Print(vectorCopy);
    std::rotate_copy(vector.begin(), vector.begin() + 5, vector.end(), vectorCopy.begin());
    std::cout << "Vector--->"; Print(vector);
    std::cout << "VectorCopy--->";Print(vectorCopy);
}
cs



리턴값)


복사된 범위의 마지막을 가리키는 Iterator를 리턴합니다.



결과)





'STL - Algorithm > Algorithm - Modifying' 카테고리의 다른 글

Algorithm - shuffle()  (0) 2017.07.13
Algorithm - random_shuffle()  (0) 2017.07.13
Algorithm - rotate()  (0) 2017.07.13
Algorithm - reverse_copy()  (0) 2017.07.13
Algorithm - reverse()  (0) 2017.07.13