I want to generate all permutation of a vector< pair<int,int> > v
...using c++ next_permutation such that permutation are generated only basis of v[i].first
irrespective of the value of v[i].second
...
example...
v.push_back(pair<int,int>(3,600));
v.push_back(pair<int,int>(2,900));
v.push_back(pair<int,int>(2,800));
I need following 3 permutation( treating (2,900) and (2,800) as same ).
(2,900) (2,800) (3,600)
(2,900) (3,600) (2,800)
(3,600) (2,900) (2,800)
But instead i get 6 permutations( (2,900) and (2,800) are being treated different )
I know it has to be done by using comparator function in next_permutation....but i am not able to....Pls help how to use comparator function...
here is the code..
int main()
{
vector< pair<int,int> > v;
v.push_back(pair<int,int>(3,600));
v.push_back(pair<int,int>(2,900));
v.push_back(pair<int,int>(2,800));
sort(v.begin(),v.end());
do
{
for(int i=0; i<v.size(); i++)
{
printf("%d %d ",v[i].first,v[i].second);
}
printf("\n");
}while( next_permutation(v.begin(),v.end()) );
return 0;
}
pair<int,int>
doesn't provide a default one.