C++ STL में Multimap क्या है?
Multimap एक associative container है जो map container के समान होता है। यह key-value और mapped value के संयोजन से बने तत्वों को एक विशिष्ट क्रम में संग्रहीत करता है। एक multimap container में एक ही key से जुड़े कई तत्व हो सकते हैं। डेटा आंतरिक रूप से हमेशा उससे जुड़ी keys की मदद से सॉर्ट किया जाता है।
multimap::crbegin() क्या है?
multimap::crbegin() C++ STL में एक अंतर्निहित फंक्शन है, जो <map> हेडर फाइल में परिभाषित है। crbegin() का अर्थ constant reverse begin है, यानी cbegin का reverse जो constant begin था, दूसरे शब्दों में, crbegin() फंक्शन उस iterator को लौटाएगा जो multimap container के अंतिम तत्व की ओर इंगित करता है। इस iterator का उपयोग multimap को संशोधित करने के लिए नहीं किया जा सकता। इसका उपयोग केवल set container को पार करने के लिए किया जा सकता है।
सिंटैक्स
mutliMap_name.crbegin();
पैरामीटर
यह फंक्शन कोई पैरामीटर स्वीकार नहीं करता।
रिटर्न वैल्यू
यह फंक्शन container के अंतिम तत्व की ओर इंगित करने वाला iterator लौटाता है।
उदाहरण
#include <bits/stdc++.h>
using namespace std;
int main() {
// container बनाएं
multimap<int, int> mul;
// emplace का उपयोग करके सम्मिलित करें
mul.emplace_hint(mul.begin(), 1, 10);
mul.emplace_hint(mul.begin(), 2, 20);
mul.emplace_hint(mul.begin(), 2, 30);
mul.emplace_hint(mul.begin(), 1, 40);
mul.emplace_hint(mul.begin(), 1, 50);
mul.emplace_hint(mul.begin(), 5, 60);
auto it = mul.crbegin();
cout << "Last element using crbegin() is: {" << it->first << ", " << it->second << "}\n";
cout << "\nElements in multimap is: \n";
cout << "KEY\tELEMENT\n";
for (auto i = mul.crbegin(); i != mul.crend(); i++) {
cout << i->first << "\t" << i->second << endl;
}
return 0;
}
आउटपुट
Last element using crbegin() is: {5, 60}
Elements in multimap is:
KEY ELEMENT
5 60
2 20
2 30
1 10
1 40
1 50
multimap::crend() क्या है?
multimap::crend() C++ STL में एक अंतर्निहित फंक्शन है, जो <map> हेडर फाइल में परिभाषित है। crend() का अर्थ constant reverse end iterator है, यानी यह cend का reverse है जो एक constant end iterator था, दूसरे शब्दों में, crend() फंक्शन उस iterator को लौटाएगा जो container से जुड़े फंक्शन की पहली स्थिति से ठीक पहले की स्थिति की ओर इंगित करता है। इस iterator का उपयोग multimap को संशोधित करने के लिए नहीं किया जा सकता। इसका उपयोग केवल multimap container को पार करने के लिए किया जा सकता है।
सिंटैक्स
newmultimap.crend();
पैरामीटर्स
यह फंक्शन कोई पैरामीटर स्वीकार नहीं करता।
रिटर्न वैल्यू
यह संबंधित container के पहले तत्व से ठीक पहले की ओर इंगित करने वाला एक iterator लौटाता है।
उदाहरण
#include <bits/stdc++.h>
using namespace std;
int main() {
// container बनाएं
multimap<int, int> mul;
// emplace का उपयोग करके सम्मिलित करें
mul.emplace_hint(mul.begin(), 1, 10);
mul.emplace_hint(mul.begin(), 2, 20);
mul.emplace_hint(mul.begin(), 2, 30);
mul.emplace_hint(mul.begin(), 1, 40);
mul.emplace_hint(mul.begin(), 1, 50);
mul.emplace_hint(mul.begin(), 5, 60);
cout << "\nElements in multimap is: \n";
cout << "KEY\tELEMENT\n";
for (auto i = mul.crbegin(); i != mul.crend(); i++) {
cout << i->first << "\t" << i->second << endl;
}
return 0;
}
आउटपुट
Elements in multimap is: KEY ELEMENT 5 60 2 20 2 30 1 10 1 40 1 50