algorithm库函数集合

不修改内容的序列操作:

algorithm库函数集合

修改内容的序列操作:

algorithm库函数集合

algorithm库函数集合

划分操作:

algorithm库函数集合

排序操作:

algorithm库函数集合

二分法查找操作:

algorithm库函数集合

集合操作:

algorithm库函数集合

堆操作:

algorithm库函数集合

最大/最小操作:

algorithm库函数集合

附上 巡防算法

  for_each(容器起始地址,容器结束地址,要执行的方法)

[html] view plain copy
#include <iostream>  
#include <algorithm>  
#include <vector>  
  
using namespace std;  
  
template<class T>  
struct plus2  
{  
    void operator()(T&x)const  
    {  
        x+=2;  
    }  
      
};  
  
void printElem(int& elem)  
{  
  cout << elem << endl;  
}  
  
  
int main()  
{  
    int ia[]={0,1,2,3,4,5,6};  
    for_each(ia,ia+7,printElem);//输出  
      
    int ib[]={7,8,9,10,11,12,13};  
    vector<int> iv(ib,ib+7);  
    for_each(iv.begin(),iv.end(),plus2<int>());//更改元素  
    for_each(iv.begin(),iv.end(),printElem);//输出  
      
      
    return 0;  
}