#include
boolabs_max(int elem1,int elem2) { if(elem1<0) elem1=-elem1; if(elem2<0) elem2=-elem2; return elem1 classCInt; ostream& operator<<(ostream&osIn,constCInt&rhs); classCInt { private: intm_nVal; public: CInt(int n=0):m_nVal(n){} CInt(constCInt&rhs):m_nVal(rhs.m_nVal){} CInt& operator=(constCInt&rhs) { m_nVal=rhs.m_nVal; return *this; } bool operator<(constCInt&rhs)const//注意const标志 { returnm_nVal inlineostream& operator<<(ostream&osIn,constCInt&rhs) { cout<<\ returnosIn; } voidalg_max(); //============================================================== int main() { alg_max(); return 0; } voidalg_max() { cout<<\ int a=6,b=-7; constint&Result1=max(a,b); cout<<\ constint&Result2=max(a,b,abs_max); cout<<\ // Comparing set containers with elements of type CInt // using the max algorithm CInt c1=1,c2=2,c3=3; set cout<<\ for(s2_Iter=s2.begin();s2_Iter!=s2.end();s2_Iter++) cout<<\s2_Iter=--s2.end(); cout<<\s3=max(s1,s2); cout<<\ for(s3_Iter=s3.begin();s3_Iter!=s3.end();s3_Iter++) cout<<\s3_Iter=--s3.end(); cout<<\ // Comparing vectors with integer elements using the max algorithm //the max algorithm vector vector for(i=0;i<=2;i++) { v1.push_back(i);//初始化向量v1 } int ii; for(ii=0;ii<=2;ii++) { v2.push_back(ii);//初始化向量v2 } int iii; for(iii=0;iii<=2;iii++) { } v3.push_back(2*iii);//初始化向量v3 cout<<\输出向量v1中的所有元素 for(Iter1=v1.begin();Iter1!=v1.end();Iter1++) cout<<*Iter1<<\cout<<\ cout<<\输出向量v2中的所有元素