您的位置:首页 > 编程语言 > C语言/C++

c++如何让自定义的类可以执行STL中的sort算法

2013-12-10 20:52 288 查看
定义排序函数:

bool Less(const Student& s1, const Student& s2)

{

return s1.name < s2.name; //可以自己设定

}

std::sort(sutVector.begin(), stuVector.end(), Less);

或者

bool operator<(const Student& s1, const Student& s2)

{

return s1.name < s2.name; //可以自己设定

}

std::sort(sutVector.begin(), stuVector.end());

或者

struct Less

{

bool operator()(const Student& s1, const Student& s2)

{

return s1.name < s2.name; //可以自己设定

}

};

std::sort(sutVector.begin(), stuVector.end(), Less());
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐