c++ - 按第二个元素对c ++中的一对向量进行排序,如果第二个相同,则根据第一个对其进行排序
问题描述
谁能解释一下它是如何工作的?
我们没有调用sortbysec
函数,但我仍然得到了正确的答案。为什么不需要传递对sortbysec
?
请解释一下,因为我对std::sort
功能的内部运作感到困惑。
bool sortbysec(const pair<int, int> &a, const pair<int, int> &b)
{
if (a.second == b.second)
return (a.first < b.first);
else
return (a.second < b.second);
}
sort(v.begin(), v.end(), sortbysec);
解决方案
推荐阅读
- sql - 在给定附加条件的情况下从 JOIN 获取单行
- git - 如何通过 SSH 访问 Bitbucket 启用访问控制?
- reactjs - 如何从一个页面路由到另一个页面?
- python - SQL 密码中的特殊字符
- r - 如何处理 R 中合并的列标题?
- apache-kafka - 如何为 Confluent Schema Registry 指定 nodePort?
- autodesk-data-management - Data Management API 获取文档的完整文件夹路径
- r - 在 Shiny 中选择单选按钮的活动选项卡
- flutter - RenderBox 未布置:RenderFittedBox#79644 relayoutBoundary=up1
- nlp - XLNetForSequenceClassification 预训练模型无法加载