CHAPTER9-9.cpp
上传用户:fjc899
上传日期:2007-07-03
资源大小:187k
文件大小:1k
- //文件名:CHAPTER9-9.cpp
- #include <set>
- #include <iostream>
- #if _MSC_VER > 1020 // if VC++ version is > 4.2
- using namespace std; // std c++ libs implemented in std
- #endif
- int main( )
- {
- set <int> s1;
- set <int>::iterator s1_Iter;
- set <int>::reverse_iterator s1_rIter;
- set <int>::const_reverse_iterator s1_crIter;
- s1.insert( 10 );
- s1.insert( 20 );
- s1.insert( 30 );
- s1_rIter = s1.rend( );
- s1_rIter--;
- cout << "The last element in the reversed set is "
- << *s1_rIter << "." << endl;
- // end can be used to terminate an iteration throught a set in a forward order
- cout << "The set is: ";
- for ( s1_Iter = s1.begin( ) ; s1_Iter != s1.end( ); s1_Iter++ )
- cout << *s1_Iter << " ";
- cout << "." << endl;
- // rend can be used to terminate an iteration throught a set in a reverse order
- cout << "The reversed set is: ";
- for ( s1_rIter = s1.rbegin( ) ; s1_rIter != s1.rend( ); s1_rIter++ )
- cout << *s1_rIter << " ";
- cout << "." << endl;
- s1_rIter = s1.rend( );
- s1_rIter--;
- s1.erase ( *s1_rIter );
- s1_rIter = s1.rend( );
- cout << "After the erasure, the last element in the "
- << "reversed set is " << *s1_rIter << "." << endl;
- }