STL算法 -------- 删除算法2

1. remove_copy()

2. remove_copy_if()


#include <iostream>
#include <algorithm>
#include <list>
#include <vector>
#include <set>
#include <iterator>

using namespace std;

template <typename T>
void Print( const T& t )
{
	for(typename T::const_iterator itr=t.begin(); itr!=t.end(); ++itr)
	{
		cout<<*itr<<' ';
	}cout<<endl;
}

int main()
{
	list<int> lst;
	
	for(int i=1; i<=6; ++i)
	{
		lst.push_back(i);
	}
	for(int i=1; i<=9; ++i)
	{
		lst.push_back(i);
	}
	Print(lst);

	multiset<int> mset;
	remove_copy_if(lst.begin(), lst.end(), inserter(mset, mset.end()),
				bind2nd(less<int>(), 4));
	Print(mset);

	remove_copy(lst.begin(), lst.end(), ostream_iterator<int>(cout, " "), 3);
	cout<<endl;
	
	remove_copy_if(lst.begin(), lst.end(), ostream_iterator<int>(cout, " "),
			bind2nd(greater<int>(), 4));

	return 0;
}


posted @ 2015-03-09 18:30  SandKing  阅读(7)  评论(0)    收藏  举报  来源