관리 메뉴

Kim's Programming

Algorithm - includes() 본문

STL - Algorithm/Algorithm - Merge

Algorithm - includes()

Programmer. 2017. 6. 24. 12:10

원형)


1
2
3
4
5
6
7
8
9
//기본형
template <class InputIterator1, class InputIterator2>
  bool includes ( InputIterator1 first1, InputIterator1 last1,
                  InputIterator2 first2, InputIterator2 last2 );
 
//사용자 정의형
template <class InputIterator1, class InputIterator2, class Compare>
  bool includes ( InputIterator1 first1, InputIterator1 last1,
                  InputIterator2 first2, InputIterator2 last2, Compare comp );
cs



의미)


정렬된 범위[Iterator first1, Iterator last1)에 있는 데이터들에 정렬된 범위 [Iterator first2,. Iterator last2)에 있는 모든 데이터를 포함하면 true를 리턴한다.



소스)


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
31
32
33
34
35
#include<iostream>
#include<algorithm>
#include<vector>
 
void Print(const std::vector<int>& target)
{
    for (std::vector<int>::const_iterator iterPos = target.cbegin(); iterPos != target.cend(); iterPos++)
        std::cout << *iterPos << " ";
    std::cout << std::endl;
}
 
void main()
{
    std::vector<int> vector = { 10,5,20,15,30 };
    std::vector<int> vector2 = { 1,3,5,7,9,11 };
    std::vector<int> vector3 = { 5,10,15,20,25,30,35,40,45,50 };
 
    std::sort(vector.begin(), vector.end());
    std::sort(vector2.begin(), vector2.end());
    Print(vector);
    Print(vector2);
    Print(vector3);
 
    if (std::includes(vector3.begin(), vector3.end(), vector.begin(), vector.end()))
        std::cout << "include!" << std::endl;
    else
        std::cout << "not! include!" << std::endl;
 
    if (std::includes(vector.begin(), vector.end(), vector2.begin(), vector2.end()))
        std::cout << "include!" << std::endl;
    else
        std::cout << "not! include!" << std::endl;
}
 
 
cs



리턴값)


[Iterator first2, Iterator last2)범위에 있는 모든 데이터들이 {Iterator first1, Iterator last1)사이에 포함되어있으면 true를 리턴하고 그 이외의 경우에 false를 리턴합니다. 



결과)




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

Algorithm - set_difference()  (0) 2017.06.24
Algorithm - set_intersection()  (0) 2017.06.24
Algorithm - set_union()  (0) 2017.06.24
Algorithm - inplace_merge()  (0) 2017.06.24
Algorithm - merge()  (0) 2017.06.24