⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 alg45.c

📁 C++Primer中文版 第三版 深入系列 Primer 第三版 著 中中文文版版潘爱民张丽译 Addison-Wesley 中国电力出版社 www.infopower.com.cn S
💻 C
字号:
#include <algorithm>
#include <vector>
#include <iostream.h>

/* generates:
   original element sequence:
   29 23 20 22 17 15 26 51 19 12 35 40 
   stable_partition on even element:
   20 22 26 12 40 29 23 17 15 51 19 
   stable_partition of less-than 25:
   23 20 22 17 15 19 12 29 26 51 35 40 
*/
	
class even_elem {
public:
	bool operator()( int elem ) {
		return elem%2 ? false : true;
	}
};
	
int main()
{
	int ia[] = { 29,23,20,22,17,15,26,51,19,12,35,40 }; 
	vector< int, allocator > vec( ia, ia+12 );
        ostream_iterator< int >  ofile( cout, " " );
		
        cout << "original element sequence:\n";
        copy( vec.begin(), vec.end(), ofile ); cout << '\n';

	stable_partition( &ia[0], &ia[12], even_elem() );

        cout << "stable_partition on even element:\n";
        copy( ia, ia+11, ofile ); cout << '\n';

	stable_partition( vec.begin(), vec.end(),
			  bind2nd(less<int>(),25)  );

        cout << "stable_partition of less-than 25:\n";
        copy( vec.begin(), vec.end(), ofile ); cout << '\n';
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -