++


swap()


template< class Type >

void

swap ( Type &ob1, Type &ob2 );

swap() ob1 ob2.

#include <algorithm>

#include <vector>

#include <iostream.h>

/* :

:

3 4 5 0 1 2

swap() :

0 1 2 3 4 5

*/

int main()

{

int ia[] = { 3, 4, 5, 0, 1, 2 };

vector< int, allocator > vec( ia, ia+6 );

for ( int ix = 0; ix < 6; ++ix )

for ( int iy = ix; iy < 6; ++iy ) {

if ( vec[iy] < vec[ ix ] )

swap( vec[iy], vec[ix] );

}

 

ostream_iterator< int > ofile( cout, " " );

 

cout << " :\n";

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

cout << " swap() "

<< " :\n";

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

}




- -  - -  - -