Мне нужно получить соответствующую пару относительно заданного значения из отсортированного вектора контейнера пары. используя «бинарный поиск». как это сделать?
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
vector<pair<int,int>> values;
values.push_back(make_pair(6,9));
values.push_back(make_pair(2,5));
values.push_back(make_pair(12,15));
sort(values.begin(), values.end()); // sorting the vector according to 'first' value
/*then the vector be like [(2,5), (6,9), (12,15)]*/
/*assume : no duplicate or overlapped pairs*/
/* I need to implement a function to get the corresponding pair related to a given value using 'binary search' method*/
/*eg:
if given_value = 7, then function should be return (6,7)
if given_value = 10, then function shold be return NULL
how i do this. is there a predefined way to do this ? */
}