Effective STL 31 Know your sorting options
来源:互联网 发布:单片机c51出租车计价器 编辑:程序博客网 时间:2024/06/07 19:45
with algorithms that do more work tend to use fewer resources listed before those that requir more:
I. partition sort
bool hasAcceptableQaulity(const Widfet& w) { // return whether w has a quality rating of 2 or better;}// move all widgets satisfying hasAcceptableQaulity to the front of widgets, // and return an iterator to the first widget that isn't satisfactoryvector<Widget>::iterator goodEnd = partition(widgets.begin(), widgets.end(), hasAcceptableQaulity);
II. stable_partition
III. nth_element
其功能是对区间 [_First, _Last) 的元素进行重排,其中位于位置 _Nth 的元素与整个区间排序后位于位置 _Nth 的元素相同,并且满足在位置 _Nth 之前的所有元素都“不大于”它和位置 _Nth 之后的所有元素都“不小于”它,而且并不保证 _Nth 的前后两个区间的所有元素保持有序。
template<class _RanIt, class _Pr> void nth_element(_RanIt _First, _RanIt _Nth, _RanIt _Last, _Pr _Pred);
bool qualityCompare(const Widget& lhs, const Widget& rhs) { // return lh's quality is greater than rh's quality}// put the best 20 elements at the front of widgets, but do not worry about t// their ordernth_element(widgets.begin(), widgets.begin() + 19, widgets.end(), qualityCompare);
IV. partial_sort
bool qualityCompare(const Widget& lhs, const Widget& rhs) { // return lh's quality is greater than rh's quality}// put the best 20 elements (in order) at the front of widgetspartital_sort(widgets.begin(), widgets.begin() + 20, widgets.end(), qualityCompare);
V. sort
VI. stable_sort
阅读全文
0 0
- Effective STL 31 Know your sorting options
- Effective STL 9 erasing options
- Effective STL 条款31
- STL sorting
- Know Your Enemy
- Does your mother know
- Know your SQL optimizer
- know your enemy 主页
- Know Your Enemy
- Know Your JavaScript (Injections)
- Know Your IDE
- Know Your Limits
- Know Your Next Commit
- know your scrnsize!
- Know Your IDE
- Know Your Limits
- Know Your Next Commit
- Chapter3.Know Your Variables
- android --系统jar包引用
- HDU1241 Oil Deposits —— DFS求连通块
- VBS中WScript.Shell对象的run和exec的使用及区别
- BZOJ 2054: 疯狂的馒头 并查集题解
- 解决安装Scrapy时报错error: Unable to find vcvarsall.bat
- Effective STL 31 Know your sorting options
- JExcel读取Excel,完成随机数对应学号,随机选取学生姓名
- [容易] UVa OJ 725 Division 暴力枚举
- 神经网络中卷积层的堆叠
- 适配器模式
- stat函数与stat结构体
- django设置时区与语言
- C# String和StringBuilder简介
- 一文说尽C++赋值运算符重载函数(operator=)