Android Ndk 学习笔记(目录)
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
class __F{
public:
void operator()(int __first){
cout << __first << endl ;
}
};
class __unary_op{
public:
int operator() (const int __first){
return __first + 9 ;
}
};
class __pred{
public:
int number ;
__pred(int number) : number(number){}
bool operator() (const int value){
return number = value;
}
};
void useForeach(){
vector<int> vectorVar;
vectorVar.insert(vectorVar.begin(), 10000);
vectorVar.insert(vectorVar.begin(), 20000);
vectorVar.insert(vectorVar.begin(), 30000);
vectorVar.insert(vectorVar.begin(), 40000);
vectorVar.insert(vectorVar.begin(), 50000);
vectorVar.insert(vectorVar.begin(), 60000);
for_each(vectorVar.begin(),vectorVar.end(),__F());
vector<int> transformResult;
transformResult.resize(vectorVar.size());
transform(vectorVar.begin(),vectorVar.end(),transformResult.begin(),__unary_op());
find(vectorVar.begin(),vectorVar.end(),10000);
find_if(vectorVar.begin(),vectorVar.end(),__pred(30000));
vector<int> vectorVarCount;
vectorVar.push_back(1);
vectorVar.push_back(2);
vectorVar.push_back(3);
vectorVar.push_back(2);
vectorVar.push_back(4);
vectorVar.push_back(6);
vectorVar.push_back(8);
vectorVar.push_back(1);
int number = count(vectorVar.begin(),vectorVar.end(),2);
cout << "等于2的个数是:" << number << endl;
number = count_if(vectorVarCount.begin(),vectorVarCount.end(),bind2nd(less<int>(),2));
cout << "等于2的个数是:" << number << endl;
number = count_if(vectorVar.begin(), vectorVar.end(), bind2nd(greater<int>(), 2));
cout << "等于2的个数是:" << number << endl;
number = count_if(vectorVar.begin(), vectorVar.end(), bind2nd(equal_to<int>(), 2));
cout << "等于2的个数是:" << number << endl;
vector<int> vectorVarMerge;
vectorVarMerge.resize(vectorVar.size()+vectorVarCount.size());
merge(vectorVar.begin(),vectorVar.end(),vectorVarCount.begin(),vectorVarCount.end(),vectorVarMerge.begin());
sort(vectorVarCount.begin(),vectorVarCount.end());
sort(vectorVarCount.begin(),vectorVarCount.end(),greater<int>());
random_shuffle(vectorVar.begin(), vectorVar.end());
vector<int> vectorCopy;
vectorCopy.resize(vectorVar.size());
copy(vectorVar.begin(),vectorVar.end(),vectorCopy.begin());
replace(vectorVar.begin(),vectorVar.end(),30000,333);
for (vector<int>::iterator it = vectorVar.begin(); it!=vectorVar.end() ; it++) {
cout << *it << endl;
}
}