STL按变量排序,然后按升序排序

Pro*_*ner 3 c++ sorting stl

我怎么能按字母顺序排序然后按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)

dav*_*igh 5

将您的两个标准扩展到词典比较:

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)