stl nth_element使用...
2010-07-29 15:01
281 查看
#include <algorithm> #include <vector> #include <ctime> #include <iostream> using namespace std; const int MAX = 50; int main(int argc, char *argv[]) { vector<int> vec; int each; int count = 10; srand((unsigned)time(NULL)); for(int i=0; i<count; i++) { each = rand() % MAX; vec.push_back(each); } cout << "before nth_element: " << endl; for(int i=0; i<count; i++) cout << vec.at(i) << " "; cout << endl; nth_element(vec.begin(), vec.begin() + 5, vec.end()); cout << "after nth_element: " << endl; for(int i=0; i<count; i++) cout << vec.at(i) << " "; cout << endl; system("PAUSE"); return EXIT_SUCCESS; }
将第N小的元素放在第N个位置...
相关文章推荐
- STL中的nth_element()方法的使用
- STL<algorithm>中的nth_element()方法的使用
- 浅谈 STL中的 nth_element() 使用方法
- STL 源码分析《2》----nth_element() 使用与源码分析
- STL 源码分析《2》----nth_element() 使用与源码分析
- STL中的nth_element()方法的使用
- STL中的nth_element()方法的使用
- STL中的nth_element()方法的使用
- STL之nth_element()(取容器中的第n大值)
- STL 源代码剖析 算法 stl_algo.h -- nth_element
- STL 源码剖析 算法 stl_algo.h -- nth_element
- 深海中的STL—nth_element
- nth_element使用
- STL函数——nth_element
- hdu 6040 Hints of sd0061(stl: nth_element(arr,arr+k,arr+n))
- STL之*min_element , *max_element ,*nth_element()[取容器中最大元素 最小元素 第n元素]
- (原創) 如何删除std::vector内的element?(使用find) (C/C++) (STL)
- STL源码解析 - nth_element
- C++之STL(五):非变动性算法源代码分析与使用示例( for_each、min_element 、find_if、search 等)
- NYOJ 124 中位数(水题,nth_element()使用练习)