#include <vector> #include <algorithm> #include <iostream>
bool greater5 ( int value ) { return value >5; }
int main( ) { using namespace std; vector <int> v1, v2; vector <int>::iterator Iter1; int i; for ( i = 0 ; i <= 10 ; i++ ) { v1.push_back( i ); } random_shuffle( v1.begin( ), v1.end( ) ); cout << "Vector v1 is ( " ; for ( Iter1 = v1.begin( ) ; Iter1 != v1.end( ) ; Iter1++ ) cout << *Iter1 << " "; cout << ")." << endl; // Partition the range with predicate greater5 partition ( v1.begin( ), v1.end( ), greater5 ); cout << "The partitioned set of elements in v1 is: ( " ; for ( Iter1 = v1.begin( ) ; Iter1 != v1.end( ) ; Iter1++ ) cout << *Iter1 << " "; cout << ")." << endl; return 0; }
//小菜给大家(主要给刚入门的)看看,不运行,能说说运行结果(大致)
[此贴子已经被作者于2004-11-12 22:21:47编辑过]