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 .
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.