偶然看到的东西,记录下来。
另外unique函数可以通过重载==运算符定义比较规则
以下转自 http://blog.csdn.net/aledavvv/article/details/8062066
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <iostream>
#include <algorithm>
#include <time.h>
using namespace std;
int coun;
bool op(int a)
{
printf("%d ",a);
coun++;
if(coun==10)
{
coun=0;
puts("");
}
return 1;
}
int main()
{
int a[1000];
coun=0;
fill(a,a+1000,1);
for_each(a,a+1000,op);
return 1;
}
#include <iostream>
#include <algorithm>
using namespace std;
bool myfn(int i, int j) { return i<j; }
int main () {
int myints[] = {3,7,2,5,6,4,9};
// using default comparison:
cout << "The smallest element is " << *min_element(myints,myints+7) << endl;
cout << "The largest element is " << *max_element(myints,myints+7) << endl;
// using function myfn as comp:
cout << "The smallest element is " << *min_element(myints,myints+7,myfn) << endl;
cout << "The largest element is " << *max_element(myints,myints+7,myfn) << endl;
return 0;
}