pair 에 대해서 lower/upper bound 할 때, second도 영향을 줌

    set<pair<int, int>> test;
    test.insert({ 10,50 });
    test.insert({ 30,10 });
    test.insert({ 50,0 });
    test.insert({ 70,60 });
    test.insert({ 100,-50 });

    auto iter = test.lower_bound({ 30,10 }); //{30,10} first가 같은경우, second보다 같거나 큰걸 찾음

    auto iter2 = test.upper_bound({ 50,0 }); //{50,0} first가 같은경우, second보다 큰걸 찾음.

 

lower든 upper든  first 로만 찾고 싶을 때,

auto iter = test.lower_bound({ 값, -INF});	// first만 고려

auto iter2 = test.upper_bound({ 값, INF});	// first만 고려

 

 

 

내림차순 컨테이너에서 lower_bound / upper_bound

  • 내림차순에서 lower_bound 는 목표보다 같거나 작은 첫 번째 요소 iter를 찾는 것.
auto iter = lower_bound (container.begin(), contaniner.end(), x, greater<type>());

 

  • 내림차순에서 upper_bound 는 목표보다 작은 첫 번째 요소 iter를 찾는 것.
auto iter = upper_bound (container.begin(), contaniner.end(), x, greater<type>());

'c, c++ 리마인드' 카테고리의 다른 글

C++ new / delete  (0) 2023.10.24
C++ this 포인터 / 멤버함수 / 가상함수  (0) 2023.10.24
ANSI, UNICODE, UTF-x  (0) 2023.09.05
c++ 데이터 파일 입출력  (0) 2023.08.27
c++ stringstream  (0) 2023.08.27

+ Recent posts