自定义set集合
#include <iostream>
#include <set>
using namespace std;
struct str
{
int x;
};
bool MyComp(const str &val1, const str &val2)
{
return val1.x<val2.x;
}
int main()
{
set<str,decltype(&MyComp)> s(MyComp);
s.insert(str{1});
s.insert(str{3});
for(auto c=s.begin(); c!=s.end(); c++)
{
cout<<(*c).x<<endl;
}
}
输出结果
1
3