我怎么能按字母顺序排序然后按int类中的变量排序?我如何组合它们,如果counter相同,它将按字母顺序返回?
// sort pages by its popularity
bool popularity(const Page &a, const Page &b) {
return a.counter > b.counter;
}
// alphabetical sort
bool alphaSort(const Page &a, const Page &b) {
return a.name < b.name;
}
// Combination?
sort(.begin(), .end(), ??)
Run Code Online (Sandbox Code Playgroud)
将您的两个标准扩展到词典比较:
bool combinedSort(const Page &a, const Page &b)
{
return a.counter > b.counter || (a.counter == b.counter && a.name < b.name);
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
125 次 |
| 最近记录: |