C++ Primer 学习中。。。
简单记录下我的学习过程 (代码为主)
//全部容器适用 nth_element(b,n,e) nth_element(b,n,e,p) 对照:partition()算法
/**------http://blog.csdn.net/u010579068------**/#include#include #include #include #include #include
#include #include using namespace std;/*****************************************//全部容器适用nth_element(b,n,e)nth_element(b,n,e,p)对照:partition()算法*****************************************//**--------------------------------------------------------------------------------------------------------------------------------------------------------------------**//*************************************************************************************std::nth_element 全部排序容器适用 algorithm--------------------------------------------------------------------------------------template void nth_element ( RandomAccessIterator first, RandomAccessIterator nth, RandomAccessIterator last );template void nth_element ( RandomAccessIterator first, RandomAccessIterator nth, RandomAccessIterator last, Compare comp );//eg:*************************************************************************************/bool myfunction (int i,int j){ return (i>j);}int main (){ int m[]= {3,4,5,6,7,2,3,4,5,6,1,2,3,4,5}; vector myvector(m,m+15); vector ::iterator it;// set some values:// for (int i=1; i<10; i++) myvector.push_back(i); // 1 2 3 4 5 6 7 8 9// random_shuffle (myvector.begin(), myvector.end()); cout << "myvector contains:(原始数据)"; for (it=myvector.begin(); it!=myvector.end(); ++it) cout << " " << *it; cout << endl;// using default comparison (operator <):// cout<<*(myvector.begin()+3)<