c++几个排序手法

1

sort(box.begin(), box.end(), [](const vector<int>& a, const vector<int>& b) { return a[0] < b[0]; });

2

sort(box.begin(), box.end(), cmp);
static bool cmp(const vector<int> &b1, const vector<int> &b2 ){
    return b1[0] > b2[0];
}

3

struct cmp{
    bool operator()(const pair<int,int>& a,const pair<int,int>& b)const{
        if(a.first == b.first) return a.second > b.second;
        return a.first < b.first;
    }
};
class Solution {
public:
    void getans(vector<pair<int, int>>& box) {
        sort(box.begin(), box.end(), cmp());  
        return;
    }
};
原文地址:https://www.cnblogs.com/wrjlinkkkkkk/p/14269510.html