cmp
bool cmp(const pair<string, long> &p1, const pair<string, long> &p2){
if(p1.second!=p2.second)
return p1.second < p2.second;
return strcmp(p1.first.c_str(),p2.first.c_str());
}
こんにちは、みんな、
の要素にvector
基づいて並べ替えようとしています。ペアの要素が等しい場合は、の要素を比較します。second
pair
second
first
pair
上記のコードを使用して、vector
含むstring
とを並べ替えていint
pair
ます。を使用して並べ替え関数を呼び出していsort_heap(vector.begin(),vector.end(),cmp);
ます。しかし、これは期待どおりに機能していないようです。