/*
题目:
给定一个 vector:v1 = [0, 0, 30, 20, 0, 0, 0, 0, 10, 0],希望通过not_equal_to 算法找到到不为零的元素,并复制到另一个 vector: v2
*/
int _tmain(int argc, _TCHAR* argv[])
{
vector<int> v1;
v1.push_back(0);
v1.push_back(0);
v1.push_back(30);
v1.push_back(20);
v1.push_back(0);
v1.push_back(0);
v1.push_back(0);
v1.push_back(0);
v1.push_back(10);
v1.push_back(0);
cout<<"=========="<<endl;
cout<<"before equal: "<<endl;
for (unsigned int i = 0; i < v1.size();i++)
{
cout<<"["<<i<<"]="<<v1[i]<<endl;
}
cout<<"=========="<<endl;
vector<int> v2;
vector<int>::iterator iter = v1.begin();
while(1){
iter = find_if(iter,v1.end(), bind2nd(not_equal_to<int>(),0));
if (iter == v1.end())
{
break;
}
v2.push_back(*iter);
iter++;//从下一个开始找
}
}
运行结果: