CHAPTER11-12.cpp
上传用户:fjc899
上传日期:2007-07-03
资源大小:187k
文件大小:1k
- //文件名:CHAPTER11-12.cpp
- #include <vector>
- #include <algorithm>
- #include <functional>
- #include <iostream>
- int main( )
- {
- using namespace std;
- vector <int> v1;
- vector <int>::iterator Iter1, Iter2;
- int i;
- for ( i = 1 ; i <= 9 ; i++ )
- { v1.push_back( i ); }
- random_shuffle( v1.begin( ), v1.end( ) );
- cout << "The original version of vector v1 is: ( " ;
- for ( Iter1 = v1.begin( ) ; Iter1 != v1.end( ) ; Iter1++ ) cout << *Iter1 << " ";
- cout << ")." << endl;
- // Shuffled once
- random_shuffle( v1.begin( ), v1.end( ));
- push_heap( v1.begin( ), v1.end( ) );
- cout << "Vector v1 after one shuffle is: ( " ;
- for ( Iter1 = v1.begin( ) ; Iter1 != v1.end( ) ; Iter1++ ) cout << *Iter1 << " ";
- cout << ")." << endl;
- // Shuffled again
- random_shuffle( v1.begin( ), v1.end( ));
- push_heap( v1.begin( ), v1.end( ) );
- cout << "Vector v1 after another shuffle is: ( " ;
- for ( Iter1 = v1.begin( ) ; Iter1 != v1.end( ) ; Iter1++ ) cout << *Iter1 << " ";
- cout << ")." << endl;
- }