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());
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());
相关文章推荐
- 如何使用JW Player来播放Flash并隐藏控制按钮和自定义播放完成后执行的JS
- 如何使用JW Player来播放Flash并隐藏控制按钮和自定义播放完成后执行的JS
- STL容器可以“装”自定义类型吗?
- 【详细】如何将Java源码打包成可执行的jar文件(windows&linux系统都是可以执行的)
- 如何利用C++ vector的sort算法对元素是自定义类型进行排序
- 如何让C++ 和 STL 为C服务
- C++面试题:介绍一下STL,具体说明STL如何实现vector。
- Andriod 如何添加自定义C++库
- [C++]内存管理器--谈论如何自定义内存分配机制
- 【C++ STL应用与实现】72: 标准库里的堆--如何使用标准库的heap算法
- Seasar如何执行自定义SQL语句-yellowcong
- 【C++ STL应用与实现】7: 如何使用std::forward_list 单链表 (since C++11)
- sql profile: 如何使用我们自定义的sql 执行计划来固定原sql执行计划 及 如何优化非绑定变量sql
- iOS 如何巧妙解决“一个任务需要等待另外一个任务完成后才可以执行”的问题
- C++ windows多线程 线程描述了进程内代码的执行路径。进程中同时可以有多个线程在执行,为了使他们能够同时运行,操作系统为每个线程轮流分配CPU时间片,为了充分地利用CPU提高软件产品的性能,一
- C/C++程序编译步骤以及如何生成可执行文件
- 如何自定义android分享功能可以分享的文件格式~
- C如何打造自己自定义参数的可执行程序
- 如何添加自定义系统菜单 - C++ & MFC
- java中的clone()方法的研究---(1)自定义的类如何才可以被clone