Pair Declaration

How to Push or Insert value in Pair

"=="

"!="

">="

"<="


Example:



#include <bits/stdc++.h>
using namespace std;
int main()

{

  pair<int, vector<int>> p;
    pair<int, string> p2;
    pair<int, int> p3;
    pair<string, vector<int>> p4;
    ///
    p.first = 2;
    p.second = {1, 2, 4, 5};
    //
    p2.first = 2;
    p2.second = "karim";

    cout << p2.first << " " << p2.second;

    for (auto u : p.second)
        cout << u << " ";
    //
    p3 = make_pair(2, 3);
    //
    p4 = {"karim", {2, 3, 4, 5, 6, 7}};
    cout << p4.first << " " << p4.second.size();
    //

    vector<pair<int, int>> v; // pair using vector

    v.push_back({6, 5});
    v.push_back({2, 3});
    v.push_back({4, 5});
    v.push_back({1, 9});

    sort(v.rbegin(), v.rend());

    for (auto u : v)
        cout << u.first << " " << u.second << endl;
    //
    pair<int, int> ar[] = {{6, 5}, {2, 3}, {4, 5}, {1, 9}}; // pair using array
    sort(ar, ar + 5);

    for (int i = 0; i < 5; i++)
    {
        cout << ar[i].first << " " << ar[i].second << endl;
    }

    pair<int, int> p(10,20);
    pair<int, int> p2(30,40);
    pair<int, string> p3(30,"hight");
    pair<int, string> p4(43,"weidth");

    // p.first = 10;
    // p.second = 20;

    // p.swap(p2);

    // (==)
   if(p3==p4)
    cout << "yes -equal" << endl;
    else
    cout << "no-equal" << endl;

    /// (!=)
    if (p != p2)
    cout << "yes-Not equal" << endl;
    else
    cout << "no-equal" << endl;

    /// (>=)
    if (p >=  p2)
    cout << "yes-grater" << endl;
    else
    cout << "no-not grater" << endl;

    /// (<=)
    if (p <=  p2)
    cout << "yes-lesser" << endl;
    else
    cout << "no-not lesser" << endl;

    cout << p4.first << " "<<p4. second<<endl;
}