The following code of lines can demonstrates you about how can you implement the equal_range() function in the C++ language :
Code:
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
bool mgretr (int k,int l)
{
return (k>l);
}
int main ()
{
int mint[] = {10,20,30,30,20,10,10,20};
vector<int> s(mint,mint+8);
pair<vector<int>::iterator,vector<int>::iterator> bounds;
sort (s.begin(), s.end());
bounds=equal_range (s.begin(), s.end(), 20);
sort (s.begin(), s.end(), mgretr);
bounds=equal_range (s.begin(), s.end(), 20, mgretr);
cout << "bounds at positions " << int(bounds.first - s.begin());
cout << " and " << int(bounds.second - s.begin()) << endl;
return 0;
}
Output :
Code:
bounds at positions 2 and 5
Bookmarks