64,654
社区成员
发帖
与我相关
我的任务
分享
int main()
{
int ia[] = { 0,1,1,2,3,5,8,13,21,55,89};
vector<int> ivec(ia,ia+sizeof(ia)/sizeof(int));
list<int> ilist(ia,ia+sizeof(ia)/sizeof(int));
show(ivec);
show(ilist);
for(list<int>::iterator p = ilist.begin();p!=ilist.end();)
{
if( *p & 0x01)
p=ilist.erase(p);
else
++p;
}
for(vector<int>::iterator q = ivec.begin();q!=ivec.end();)
{
if(!(*q & 0x01) )
q=ivec.erase(q);
else
++q;
}
show(ivec);
show(ilist);
return 0;
}
#include <algorithm>
#include <list>
#include <vector>
using namespace std;
bool f(int i)
{
return i & 0x01;
}
bool f1(int i)
{
return !(i & 0x01);
}
int main()
{
int ia[] = { 0,1,1,2,3,5,8,13,21,55,89};
vector<int> ivec(ia,ia+sizeof(ia)/sizeof(int));
list<int> ilist(ia,ia+sizeof(ia)/sizeof(int));
list<int>::iterator p;
do
{
p = find_if(ilist.begin(), ilist.end(), f);
if (p!=ilist.end())
{
ilist.erase(p);
continue;
}
break;
}while(true);
vector<int>::iterator pp;
do
{
pp = find_if(ivec.begin(), ivec.end(), f1);
if (pp != ivec.end())
{
ivec.erase(pp);
continue;
}
break;
}while(true);
return 0;
}