このようなマップを定義しました
typedef std::vector< int > aVector;
typedef std::map< int, aVector > aMap;
aMap theMap;
マップに最終的にこのような要素が含まれていると仮定します
10 [0 3 7] size=3
12 [40 2 30 3 10] size=5
20 [5 10] size=2
25 [6] size=1
ベクトルのサイズでソートしたい (例: theMap->second.size())。したがって、結果は次のようになります
5 3 2 1
それを行う最も速い方法は何ですか?基本的な考え方は、サイズを別のベクトルにプッシュしてから、次のように sort() を呼び出すことです。
aVector v, sorted;
aMap::iterator it = theMap.begin();
for (; it != theMap.end(); ++it) {
v.push_back(it->second.size());
}
// using std sort!!
より良いオプションはありますか?