通过从头到尾(就是你代进去的那两个迭代器的位置)遍历线性表查找来实现的,复杂度O(n)。
#include
#include
#include
#include
using namespace std;
struct my_struct {
my_struct():a(0), b(0) { }
int a;
int b;
};
struct my_equal_to {
public:
my_equal_to(int n):num(n) { }
bool operator () (const my_struct& my) const
{
if (my.a == num)
return true;
else
return false;
}
int num;
};
struct my_not_equal_to {
public:
my_not_equal_to(int n):num(n) { }
bool operator () (const my_struct& my) const
{
if (my.a == num)
return false;
else
return true;
}
int num;
};
int main ()
{
vector
my_struct temp;
temp.a = 1000;
temp.b = 100;
my_struct temp1;
temp1.a = 100;
temp1.b = 10;
my_struct temp2;
temp2.a = 20;
temp2.b = 1;
my_struct temp3;
temp3.a = 20;
temp3.b = 3;
my.push_back(temp);
my.push_back(temp1);
my.push_back(temp2);
my.push_back(temp3);
vector
if (riter != my.rend())
cout << riter->a << '\t' << riter->b << endl;
else
cout << "No.1 Not Find" << endl;
vector
if (iter != my.end())
cout << iter->a << '\t' << iter->b << endl;
else
cout << "No.2 Not Find" << endl;
vector
remove_copy_if (my.begin(), my.end(), back_inserter(my2), my_not_equal_to(20));
for (vector
if(citer != my2.end())
cout << "a: " << citer->a << "\tb: " << citer->b << endl;
}