CHAPTER8-37.cpp
上传用户:fjc899
上传日期:2007-07-03
资源大小:187k
文件大小:1k
源码类别:

STL

开发平台:

C/C++

  1. //文件名:CHAPTER8-37.cpp
  2. #include <list>
  3. #include <iostream>
  4. #if _MSC_VER > 1020   // if VC++ version is > 4.2
  5.    using namespace std;  // std c++ libs implemented in std
  6. #endif
  7. int main( )
  8. {
  9.    using namespace std;
  10.    list <int> c1;
  11.    list <int>::iterator c1_Iter;
  12.    c1.push_back( 20 );
  13.    c1.push_back( 10 );
  14.    c1.push_back( 30 );
  15.    cout << "Before sorting: c1 =";
  16.    for ( c1_Iter = c1.begin( ); c1_Iter != c1.end( ); c1_Iter++ )
  17.       cout << " " << *c1_Iter;
  18.    cout << endl;
  19.    c1.sort( );
  20.    cout << "After sorting c1 =";
  21.    for ( c1_Iter = c1.begin( ); c1_Iter != c1.end( ); c1_Iter++ )
  22.       cout << " " << *c1_Iter;
  23.    cout << endl;
  24.    c1.sort( greater<int>( ) );
  25.    cout << "After sorting with 'greater than' operation, c1 =";
  26.    for ( c1_Iter = c1.begin( ); c1_Iter != c1.end( ); c1_Iter++ )
  27.       cout << " " << *c1_Iter;
  28.    cout << endl;
  29.    return 0;
  30. }