working link here
https://www.onlinegdb.com/edit/r1rq9WeF8
/******************************************************************************
Online C++ Compiler.
Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.
*******************************************************************************/
#include <iostream>
#include<vector>
#include<map>
#include<algorithm>
using namespace std;
template<typename T>
bool sort_map(T a,T b)
{
return a.second<b.second;
}
int main()
{
map<string,int> newMap;
vector<string> names={"manish","sachin","deepak"};
vector<int> sal={8900000,7100,1232210};
vector <pair<string,int>> myData;
for(int i=0;i<names.size();i++)
{
newMap[names[i]]=sal[i];
}
//show map
for(auto v:newMap)
{
pair<string,int> newPair;
newPair=make_pair(v.first,v.second);
myData.push_back(newPair);
}
sort(myData.begin(),myData.end(),sort_map<pair<string,int>>);
for(auto x:myData)
{
std::cout <<x.first<<"==="<< x.second << std::endl;
}
}
https://www.onlinegdb.com/edit/r1rq9WeF8
/******************************************************************************
Online C++ Compiler.
Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.
*******************************************************************************/
#include <iostream>
#include<vector>
#include<map>
#include<algorithm>
using namespace std;
template<typename T>
bool sort_map(T a,T b)
{
return a.second<b.second;
}
int main()
{
map<string,int> newMap;
vector<string> names={"manish","sachin","deepak"};
vector<int> sal={8900000,7100,1232210};
vector <pair<string,int>> myData;
for(int i=0;i<names.size();i++)
{
newMap[names[i]]=sal[i];
}
//show map
for(auto v:newMap)
{
pair<string,int> newPair;
newPair=make_pair(v.first,v.second);
myData.push_back(newPair);
}
sort(myData.begin(),myData.end(),sort_map<pair<string,int>>);
for(auto x:myData)
{
std::cout <<x.first<<"==="<< x.second << std::endl;
}
}
Comments
Post a Comment