アルゴリズム2-remove_を削除copy()

1280 ワード

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

using namespace std;

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

	for (list<int>::iterator iter = ilist.begin(); iter != ilist.end(); ++iter)
		cout << *iter << ' ';
	cout << endl; 
	cout << endl << endl;
	multiset<int> iset; // multiset      ,          ,
	remove_copy_if(ilist.begin(), ilist.end(),
		inserter(iset, iset.end()),
		bind2nd(less<int>(), 4)); //     4  ,bind2nd()         ,less<type>()          ,
	for (multiset<int>::iterator iter =iset.begin(); iter != iset.end(); ++iter)
		cout << *iter << ' ';
	cout << endl; //   4 4 5 5 6 6 7 8 9
	remove_copy(ilist.begin(), ilist.end(), ostream_iterator<int>(cout, " "), 3);
	cout << endl; //  ilist    3   copy ilist ,
	remove_copy_if(ilist.begin(), ilist.end(), ostream_iterator<int>(cout, " "), bind2nd(greater<int>(), 4));//     ilist    4     copy    cout ,
	cout << endl;


	return 0;
}