Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
降順でソートする必要がある二重リンクリストがあります。STL アルゴリズム クラスは使用できますが、他は使用できません。これを行うことができるアルゴリズム関数はありますか、それともゼロから書く必要があるものですか?
次のような独自の比較関数を書くことができます
bool compare(const T& first, const T& second) { return (second<first); }
whereTはリスト内の要素のタイプであり、次に使用します
T
std::sort(list.begin(),list.end(),compare)
もちろん、リスト内の要素がプリミティブ型でない場合は、 を返す独自の比較を作成する必要がありますbool。
bool