++


stable_partition()


template< class BidirectionalIterator, class Predicate >

BidirectionalIterator

stable_partition( BidirectionalIterator first,

BidirectionalIterator last,

Predicate pred );

stable_partition() , partition(), . , partition(), stable_partition().

#include <algorithm>

#include <vector>

#include <iostream.h>

/* :

:

29 23 20 22 17 15 26 51 19 12 35 40

:

20 22 26 12 40 29 23 17 15 51 19

, 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 << " :\n";

copy( vec.begin(), vec.end(), ofile ); cout << '\n';

 

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

 

cout << " :\n";

copy( ia, ia+11, ofile ); cout << '\n';

 

stable_partition( vec.begin(), vec.end(),

bind2nd(less<int>(),25) );

cout << " , 25:\n";

copy( vec.begin(), vec.end(), ofile ); cout << '\n';

}




- -  - -  - -