관리 메뉴

Kim's Programming

Algorithm - reverse_copy() 본문

STL - Algorithm/Algorithm - Modifying

Algorithm - reverse_copy()

Programmer. 2017. 7. 13. 13:45

원형)


1
2
3
template <class BidirectionalIterator, class OutputIterator>
  OutputIterator reverse_copy (BidirectionalIterator first,
                               BidirectionalIterator last, OutputIterator result);
cs



의미)


[Iterator first, Iterator last)사이의 데이터를 역순으로 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::reverse_copy(vector.begin(), vector.end(), vectorCopy.begin());
    std::cout << "Vector--->"; Print(vector);
    std::cout << "VectorCopy--->";Print(vectorCopy);
}
cs



리턴값)


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



결과)






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

Algorithm - rotate_copy()  (0) 2017.07.13
Algorithm - rotate()  (0) 2017.07.13
Algorithm - reverse()  (0) 2017.07.13
Algorithm - unique_copy()  (0) 2017.07.13
Algorithm - unique()  (0) 2017.07.13