CHAPTER8-39.cpp
上传用户:fjc899
上传日期:2007-07-03
资源大小:187k
文件大小:1k
- //文件名:CHAPTER8-39.cpp
- #include <list>
- #include <iostream>
- #if _MSC_VER > 1020 // if VC++ version is > 4.2
- using namespace std; // std c++ libs implemented in std
- #endif
- int main( )
- {
- list <int> c1;
- list <int>::iterator c1_Iter, c2_Iter,c3_Iter;
- not_equal_to<int> mypred;
- c1.push_back( -10 );
- c1.push_back( 10 );
- c1.push_back( 10 );
- c1.push_back( 20 );
- c1.push_back( 20 );
- c1.push_back( -10 );
- cout << "The initial list is c1 =";
- for ( c1_Iter = c1.begin( ); c1_Iter != c1.end( ); c1_Iter++ )
- cout << " " << *c1_Iter;
- cout << endl;
- list <int> c2 = c1;
- c2.unique( );
- cout << "After removing successive duplicate elements, c2 =";
- for ( c2_Iter = c2.begin( ); c2_Iter != c2.end( ); c2_Iter++ )
- cout << " " << *c2_Iter;
- cout << endl;
- list <int> c3 = c2;
- c3.unique( mypred );
- cout << "After removing successive unequal elements, c3 =";
- for ( c3_Iter = c3.begin( ); c3_Iter != c3.end( ); c3_Iter++ )
- cout << " " << *c3_Iter;
- cout << endl;
- }