struct node{
int index;
int count;
};
map<int,struct node *> m1;
bool compare(struct node* a, struct node* b) {
if(a->count>b->count)
return 1;
if(a->count==b->count && a->index<b->index)
return 1;
return 0;
}
大きなカウント値に基づいてマップを並べ替えることができますか?カウントがより低いインデックス値に基づいて等しいかどうかを調べることはできますか?stlを使ってC++の値に基づいてマップをソートする方法は?
方法は、ベクトルのすべての値をプッシュし、並べ替えを実行することです。優先順位キューを使用してソートを行う方法は他にありますか?
priority_queue<pair<int,struct node *>, vector<int,struct node *>, compare> pq(m1.begin(),m1.end());
上記の比較機能を提供しました。
'map'値によって... – Jarod42
マップがすでにソートされていない、キーによってソートされ、それがこれを行うにはキー(あなたのケースでは、' int')を使用していますソート。 – CoryKramer
マップを 'ソートできません。 – NathanOliver