관리 메뉴

Kim's Programming

Algorithm - iter_swap() 본문

STL - Algorithm/Algorithm - Modifying

Algorithm - iter_swap()

Programmer. 2017. 7. 12. 01:00

원형)


1
2
3
//기본형
template <class ForwardIterator1, class ForwardIterator2>
  void iter_swap (ForwardIterator1 a, ForwardIterator2 b);
cs



의미)


Iterator a와 Iterator b가 가리키고 있는 값들을 교체합니다.



소스)


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



리턴값)


없음



결과)






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

Algorithm - replace()  (0) 2017.07.12
Algorithm - transform()  (0) 2017.07.12
Algorithm - swap_ranges()  (0) 2017.07.12
Algorithm - swap()  (0) 2017.07.12
Algorithm - copy_backward()  (0) 2017.07.12