C++ STL में Set lower_bound() फ़ंक्शन कंटेनर में उस एलिमेंट की ओर इंगित करने वाले इटरेटर को लौटाता है जो पैरामीटर में पास किए गए k के बराबर है। यदि k सेट कंटेनर में मौजूद नहीं है, तो फ़ंक्शन k से तुरंत अगले एलिमेंट की ओर इंगित करने वाले इटरेटर को लौटाता है जो k से थोड़ा बड़ा है।
एल्गोरिथम
Begin Initialize an empty set container s. Initializing a set container as inetrator. Insert some elements in s set container. Call function to find the lower bound value of a given key, which is passed to iter set container. Print the lower bound value of the given key. End.
उदाहरण कोड
#include<iostream> #include <bits/stdc++.h> using namespace std; int main() { set<int> s; //एक खाली सेट कंटेनर घोषित करना set<int>::iterator iter; //एक सेट कंटेनर को इटरेटर के रूप में घोषित करना जो निचली सीमा मान की ओर इंगित करेगा s.insert(7); //सेट कंटेनर s में एलिमेंट्स डालना s.insert(6); s.insert(1); s.insert(4); s.insert(2); s.insert(9); s.insert(10); iter = s.lower_bound(4); //पैरामीटर द्वारा एक कुंजी पास करके उसकी निचली सीमा खोजना cout <<"The lower bound of 4 is: "<< *iter << " "<<endl; //निचली सीमा मान प्रिंट करना iter = s.lower_bound(5); cout <<"The lower bound of 5 is: " <<*iter << " "<<endl; iter = s.lower_bound(30); cout <<"The lower bound of 30 is: " <<*iter << " "<<endl; return 0; }
आउटपुट
The lower bound of 4 is: 4 The lower bound of 5 is: 6 The lower bound of 30 is: 7