Mat*_*132 -2 c++ sorting algorithm class vector
欢迎,我上课了
Class test{
string a;
string b;
}
Run Code Online (Sandbox Code Playgroud)
在主要
vector<test> t;
Run Code Online (Sandbox Code Playgroud)
以及如何按提交排序?排序ASC和DESC?我不知道怎么做这个soritng
std::sort与自定义比较器配合使用:
bool less_by_a(const test& lhs, const test& rhs)
{
return lhs.a < rhs.a;
}
Run Code Online (Sandbox Code Playgroud)
然后
#include <algorithm>
...
std::sort(t.begin(), t.end(), less_by_a);
Run Code Online (Sandbox Code Playgroud)
并且类似地对于大于a变体.
| 归档时间: |
|
| 查看次数: |
88 次 |
| 最近记录: |