基于大小()排序向量

ase*_*eem 5 c++ sorting vector

我有一个二维矢量,如vector < vector < coordinates > > v( points);坐标类是:

class coordinate{
    public :
    int x;
    int y;
    coordinate(){
        x=0;
        y=0;
    }

};
Run Code Online (Sandbox Code Playgroud)

并且点是20.如何基于v [i] .size()对各个向量v [i]进行排序,即基于在v [i]中推送的坐标对象的数量.???

Wil*_*ill 14

1)根据大小制作一个比较两个向量的函数:

bool less_vectors(const vector& a,const vector& b) {
   return a.size() < b.size();
}
Run Code Online (Sandbox Code Playgroud)

2)与它一起排序

sort(v.begin(),v.end(),less_vectors);
Run Code Online (Sandbox Code Playgroud)