标签:style blog http color 使用 os
本文为senlie原创,转载请保留此地址:http://blog.csdn.net/zhengsenlie
partial_sort / partial_sort_copy
-----------------------------------------------------------------------------------------------------------------------------------------
template <class RandomAccessIterator> inline void partial_sort(RandomAccessIterator first, RandomAccessIterator middle, RandomAccessIterator last) { __partial_sort(first, middle, last, value_type(first)); } template <class RandomAccessIterator, class T> void __partial_sort(RandomAccessIterator first, RandomAccessIterator middle, RandomAccessIterator last, T*) { make_heap(first, middle); for (RandomAccessIterator i = middle; i < last; ++i) if (*i < *first) __pop_heap(first, middle, i, T(*i), distance_type(first)); sort_heap(first, middle); }
int A[] = {7, 2, 6, 11, 9, 3, 12, 10, 8, 4, 1, 5}; const int N = sizeof(A) / sizeof(int); partial_sort(A, A + 5, A + N); copy(A, A + N, ostream_iterator<int>(cout, " ")); // The printed result is "1 2 3 4 5 11 12 10 9 8 7 6".
STL 源码剖析 算法 stl_algo.h -- partial_sort / partial_sort_copy,布布扣,bubuko.com
STL 源码剖析 算法 stl_algo.h -- partial_sort / partial_sort_copy
标签:style blog http color 使用 os
原文地址:http://blog.csdn.net/zhengsenlie/article/details/37994963