Computer >> कंप्यूटर ट्यूटोरियल >  >> प्रोग्रामिंग >> C++

C++ STL में unordered_multimap swap() फ़ंक्शन


C++ STL में unordered_multimap swap() फ़ंक्शन एक मल्टीमैप के एलिमेंट्स को उसी आकार और प्रकार के दूसरे मल्टीमैप से स्वैप करने के लिए उपयोग किया जाता है।

एल्गोरिथम

Begin    Declaring two empty map container m, m1.    Insert some values in both m, m1 map containers.    Perform swap() function to swap the values of m, m1 map containers.    Printing the swapped values of m map container.    Printing the swapped values of m1 map container. End.

उदाहरण कोड

#include<iostream> #include <bits/stdc++.h> using namespace std; int main() {    unordered_map<char, int> m,m1; // m, m1 को खाली मैप कंटेनर के रूप में घोषित करना    m.insert (pair<char, int>('b', 10)); //मैप कंटेनर में मान डालना    m.insert (pair<char, int>('c',30));    m.insert (pair<char, int>('d',40));    m1.insert (pair<char, int>('a', 20));    m1.insert (pair<char, int>('e',70));    m1.insert (pair<char, int>('f',60));    m.swap(m1); // दो मैप कंटेनर के मान स्वैप करना।    cout << "\n Key and values of 1st set are:";    for (auto it = m.begin(); it != m.end(); it++) {       cout << "{" << it->first << ", " << it->second << "} "; // m मैप कंटेनर के स्वैप किए गए मान प्रिंट करना    }    cout << "\n Key and values of 2nd set are:"; // m1 मैप कंटेनर के स्वैप किए गए मान प्रिंट करना    for (auto it = m1.begin(); it != m1.end(); it++) {       cout << "{" << it->first << ", " << it->second << "} ";    }    return 0; }

आउटपुट

Key and values of 1st set are: {f, 60} {a, 20} {e, 70} Key and values of 2nd set are: {d, 40} {b, 10} {c, 30}.

  1. - C++ STL में atanh() फ़ंक्शन

    atanh() फ़ंक्शन atanh() फ़ंक्शन आर्क हाइपरबोलिक टैंजेंट (व्युत्क्रम हाइपरबोलिक टैंजेंट) लौटाता है। <cmath> हेडर में परिभाषित (C++11 से)। सिंटैक्स atanh(var) पैरामीटर: var - float, double, या long double। मान -1 और 1 के बीच होना चाहिए (अनन्य)। वापसी मान आर्क हाइपरबोलिक टैंजेंट मान (रेडियन मे

  1. - C++ STL में cosh() फ़ंक्शन

    cosh() फ़ंक्शन cosh() फ़ंक्शन दिए गए कोण (रेडियन में) का हाइपरबोलिक कोसाइन लौटाता है। <cmath> हेडर में परिभाषित। सिंटैक्स cosh(var) पैरामीटर: var - float, double, या long double। वापसी मान हाइपरबोलिक कोसाइन मान, सीमा: [1, ∞)। उदाहरण 1: रेडियन इनपुट #include <iostream> #include <cm

  1. - C++ STL में sinh() फ़ंक्शन

    sinh() फ़ंक्शन sinh() फ़ंक्शन दिए गए कोण (रेडियन में) का हाइपरबोलिक साइन लौटाता है। <cmath> हेडर में परिभाषित। सिंटैक्स sinh(var) पैरामीटर: var - float, double, या long double। वापसी मान हाइपरबोलिक साइन मान, सीमा: (-∞, ∞)। उदाहरण 1: रेडियन इनपुट #include <iostream> #include <cmath