CHAPTER7-15.cpp
Upload User: fjc899
Upload Date: 2007-07-03
Package Size: 187k
Code Size: 1k
Category:

STL

Development Platform:

C/C++

  1. //文件名:CHAPTER7-15.cpp
  2. #include <deque>
  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.    deque <int> c1, c2, c3;
  10.    deque <int>::iterator c1_Iter;
  11.    c1.push_back( 1 );
  12.    c1.push_back( 2 );
  13.    c1.push_back( 3 );
  14.    c2.push_back( 10 );
  15.    c2.push_back( 20 );
  16.    c3.push_back( 100 );
  17.    cout << "The original deque c1 is: ";
  18.    for ( c1_Iter = c1.begin( ); c1_Iter != c1.end( ); c1_Iter++ )
  19.       cout << *c1_Iter << " ";
  20.    cout << endl;
  21.    c1.swap( c2 ); // 把c1和 c2两个容器中的内容进行相互交换
  22.    cout << "After swapping with c2, deque c1 is: ";
  23.    for ( c1_Iter = c1.begin( ); c1_Iter != c1.end( ); c1_Iter++ )
  24.       cout << *c1_Iter << " ";
  25.    cout << endl;
  26.    swap( c1,c3 ); // 把c1和 c3两个容器中的内容进行相互交换
  27.    cout << "After swapping with c3, deque c1 is: ";
  28.    for ( c1_Iter = c1.begin( ); c1_Iter != c1.end( ); c1_Iter++ )
  29.       cout << *c1_Iter << " ";
  30.    cout << endl;
  31.    return 0;
  32. }