CHAPTER11-13.cpp
上传用户:fjc899
上传日期:2007-07-03
资源大小:187k
文件大小:1k
- //文件名:CHAPTER11-13.cpp
- #include <vector>
- #include <algorithm>
- #include <iostream>
- int main( ) {
- using namespace std;
- vector <int> v1;
- vector <int>::iterator Iter1, Iter2, new_end;
- int i;
- for ( i = 0 ; i <= 9 ; i++ ) {v1.push_back( i );}
- int ii;
- for ( ii = 0 ; ii <= 3 ; ii++ ) {v1.push_back( 7 ); }
- random_shuffle ( v1.begin( ), v1.end( ) );
- cout << "Vector v1 is ( " ;
- for ( Iter1 = v1.begin( ) ; Iter1 != v1.end( ) ; Iter1++ ) cout << *Iter1 << " ";
- cout << ")." << endl;
- // Remove elements with a value of 7
- new_end = remove ( v1.begin( ), v1.end( ), 7 );
- cout << "Vector v1 with value 7 removed is ( " ;
- for ( Iter1 = v1.begin( ) ; Iter1 != v1.end( ) ; Iter1++ ) cout << *Iter1 << " ";
- cout << ")." << endl;
- // To change the sequence size, use erase
- v1.erase (new_end, v1.end( ) );
- cout << "Vector v1 resized with value 7 removed is ( " ;
- for ( Iter1 = v1.begin( ) ; Iter1 != v1.end( ) ; Iter1++ ) cout << *Iter1 << " ";
- cout << ")." << endl;
- }