map容器会自动根据key的值进行排序,要想要map容器中的内容根据value中的值进行排序
可先把map中的内容拷贝到vector容器中,然后再用sort排序
PointCloud.h
typedef struct PitArea
{
int PointNum;
float height;
}Pit;
static bool cmp_by_value(const pair<int,Pit> &x, const pair<int,Pit> &y);
PointCloud.cpp
vector<pair<int,Pit> > v(cmap.begin(),cmap.end());
std::sort(v.begin(), v.end(), &CPointCloud::cmp_by_value);
bool CPointCloud::cmp_by_value(const pair<int,Pit> &x, const pair<int,Pit> &y)
{
return x.second.PointNum>y.second.PointNum;//按value中PointNum的降序排列
}