관리 메뉴

Kim's Programming

Algorithm - reverse() 본문

STL - Algorithm/Algorithm - Modifying

Algorithm - reverse()

Programmer. 2017. 7. 13. 13:10

워형)


1
2
template <class BidirectionalIterator>
  void reverse (BidirectionalIterator first, BidirectionalIterator last);
cs



의미)


[Iterator first, Iterator last) 사이에있는 원소들의 순서를 반전합니다.


소스)


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#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::cout << "Vector--->"; Print(vector);
    std::reverse(vector.begin(), vector.end());
    std::cout << "Vector--->"; Print(vector);
}
cs



리턴값)


없음



결과)




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

Algorithm - rotate()  (0) 2017.07.13
Algorithm - reverse_copy()  (0) 2017.07.13
Algorithm - unique_copy()  (0) 2017.07.13
Algorithm - unique()  (0) 2017.07.13
Algorithm - remove_copy_if()  (0) 2017.07.13