I am trying to sort vector of pairs by second element.But it is not working instead it is showing stl_algo.h file and showing error. Here is the code below. Please ignore my bits header and using namespace std.And I have already read this > How do I sort a vector of pairs based on the second element of the pair?
#include<bits/stdc++.h>
using namespace std;
struct sort_pred
{
bool comp(pair< pair<int,int> , double >&l, pair< pair<int,int> , double >&r)
{
return l.second<r.second;
}
};
int main()
{
vector< pair< pair<int,int> ,double > >arr;
int n;
scanf("%d",&n);
int w,v;
pair< pair<int,int> ,double >temp;
for(int i=0;i<n;i++)
{
scanf("%d%d",&w,&v);
temp.first.first=w;
temp.first.second=v;
temp.second=w*1.00/v;
arr.push_back(temp);
}
sort(arr.begin(),arr.end(),sort_pred());
for(int i=0;i<n;i++)
{
printf("%d %d %f\n",arr[i].first.first,arr[i].first.second,arr[i].second);
}
return 0;
}