chapter8-38.cpp

来自「C++STL程序员开发指南」· C++ 代码 · 共 52 行

CPP
52
字号
//文件名:CHAPTER8-38.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, c2, c3, c4;
   list <int>::iterator c1_Iter, c2_Iter, w_Iter, f_Iter, l_Iter;
   c1.push_back( 10 );
   c1.push_back( 11 );
   c2.push_back( 12 );
   c2.push_back( 20 );
   c2.push_back( 21 );
   c3.push_back( 30 );
   c3.push_back( 31 );
   c4.push_back( 40 );
   c4.push_back( 41 );
   c4.push_back( 42 );
   cout << "c1 =";
   for ( c1_Iter = c1.begin( ); c1_Iter != c1.end( ); c1_Iter++ )
      cout << " " << *c1_Iter;
   cout << endl;
   cout << "c2 =";
   for ( c2_Iter = c2.begin( ); c2_Iter != c2.end( ); c2_Iter++ )
      cout << " " << *c2_Iter;
   cout << endl;
   w_Iter = c2.begin( );
   w_Iter++;
   c2.splice( w_Iter,c1 );
   cout << "After splicing c1 into c2: c2 =";
   for ( c2_Iter = c2.begin( ); c2_Iter != c2.end( ); c2_Iter++ )
      cout << " " << *c2_Iter;
   cout << endl;
   f_Iter = c3.begin( );
   c2.splice( w_Iter,c3, f_Iter );
   cout << "After splicing the first element of c3 into c2: c2 =";
   for ( c2_Iter = c2.begin( ); c2_Iter != c2.end( ); c2_Iter++ )
      cout << " " << *c2_Iter;
   cout << endl;
   f_Iter = c4.begin( );
   l_Iter = c4.end( );
   l_Iter--;
   c2.splice( w_Iter,c4, f_Iter, l_Iter );
   cout << "After splicing a range of c4 into c2: c2 =";
   for ( c2_Iter = c2.begin( ); c2_Iter != c2.end( ); c2_Iter++ )
      cout << " " << *c2_Iter;
   cout << endl;
   return 0;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?