इस ट्यूटोरियल में, हम C++ STL में multiset upper_bound() को समझने के लिए एक प्रोग्राम पर चर्चा करेंगे।
फंक्शन upper_bound() एक तत्व का पॉइंटर लौटाता है जो पैरामीटर के रूप में प्रदान किए गए से बड़ा होता है, अन्यथा यह कंटेनर में अंतिम तत्व का पॉइंटर लौटाता है।
उदाहरण
#include <bits/stdc++.h>
using namespace std;
int main(){
multiset<int> s;
s.insert(1);
s.insert(3);
s.insert(3);
s.insert(5);
s.insert(4);
cout << "The multiset elements are: ";
for (auto it = s.begin(); it != s.end(); it++)
cout << *it << " ";
auto it = s.upper_bound(3);
cout << "\nThe upper bound of key 3 is ";
cout << (*it) << endl;
it = s.upper_bound(2);
cout << "The upper bound of key 2 is ";
cout << (*it) << endl;
it = s.upper_bound(10);
cout << "The upper bound of key 10 is ";
cout << (*it) << endl;
return 0;
}
आउटपुट
The multiset elements are: 1 3 3 4 5 The upper bound of key 3 is 4 The upper bound of key 2 is 3 The upper bound of key 10 is 5