In the code sort(A.begin(),A.end());
where A
is defined as vector<pair<int,pair<int,int>>> A;
.
If I call the sort
method, then on which basis will sorting be done?
In the code sort(A.begin(),A.end());
where A
is defined as vector<pair<int,pair<int,int>>> A;
.
If I call the sort
method, then on which basis will sorting be done?
It will compare using the operator <
for the std::pair
, specified here.
It compares the elements lexicographically on the first
element first, and if they are equal, then on the second
element.
Given the complex type here pair<int,pair<int,int>>
, it may be a better idea to the give the std::sort
algorithm a custom comparator. Make sure that the functor provided fulfils the requirements of the Compare concept, that being strict weak ordering.