STL - Container/Container - Set

Set - upper_bound()

Programmer. 2016. 2. 1. 01:44

소스)


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include<set>
#include<iostream>
 
void print(std::set<int> Target_Set)
{
    for (std::set<int>::iterator IterPos = Target_Set.begin(); IterPos != Target_Set.end(); ++IterPos)
        std::cout << *IterPos << " ";
    std::cout << std::endl;
}
 
void main()
{
    std::set<int> Set = { 1,3,5,7,9,11 };
    
    print(Set);
    std::cout << *Set.upper_bound(3<< std::endl;
    print(Set);
}
cs


내용)


upper_bound(x)함수는 정렬순서에서 x보다 크면서 가장 작은 값을 가리키는 iterator를 리턴합니다. (같은 순위 제외)


결과)