इस ट्यूटोरियल में, हम C++ STL में map equal_range को समझने के लिए एक प्रोग्राम पर चर्चा करेंगे।
यह फंक्शन इटरेटर्स की एक जोड़ी लौटाता है जो कंटेनर में उस रेंज को बांधता है जिसमें दिए गए पैरामीटर के समतुल्य कुंजी रहती है।
उदाहरण
#include <bits/stdc++.h>
using namespace std;
int main() {
// कंटेनर इनिशियलाइज़ करना
map<int, int> mp;
mp.insert({ 4, 30 });
mp.insert({ 1, 40 });
mp.insert({ 6, 60 });
pair<map<int, int>::iterator, map<int, int>::iterator> it;
it = mp.equal_range(1);
cout << "The lower bound is " << it.first->first << ":" << it.first->second;
cout << "\nThe upper bound is " << it.second->first << ":" << it.second->second;
return 0;
}
आउटपुट
The lower bound is 1:40 The upper bound is 4:30