728x90
upper_bound
-
[c++] lower_bound, upper_bound 함수Programming/c++ 2022. 9. 15. 14:36
lower_bound, upper_bound 란? c++에서 이진 탐색으로 원소를 탐색하는 기능을 합니다. lower_bound 찾으려는 target 값보다 같거나 큰 숫자 가 배열 몇 번째에서 처음 등장하는지 찾는 함수 -사용 조건 : 탐색을 진행할 배열 및 벡터는 오름차순으로 정렬되어 있어야 한다. lower_bound 예제 int arr[6] = { 1,2,3,4,5,6 }; int index = lower_bound(arr, arr + 6, 6) - arr; #include #include #include using namespace std; int main() { vector nums = { 1,3,5,6 }; int target = 4; auto a = lower_bound(nums.begin..