共用方式為


deque::swap

交換兩個雙佇列的項目。

void swap( 
   deque<Type, Allocator>& _Right 
); 
friend void swap( 
   deque<Type, Allocator>& _Left, 
   deque<Type, Allocator>& _Right 
) 
template<class Type, class Allocator> 
void swap( 
   deque< Type, Allocator>& _Left,  
   deque< Type, Allocator>& _Right 
);

參數

  • _Right
    項目會交換這些雙向佇列 _Left的雙向佇列提供項目會交換或雙向佇列。

  • _Left
    項目會交換這些雙向佇列 _Right的兩個佇列。

範例

// deque_swap.cpp
// compile with: /EHsc
#include <deque>
#include <iostream>

int main( ) 
{
   using namespace std;
   deque <int> c1, c2, c3;
   deque <int>::iterator c1_Iter;

   c1.push_back( 1 );
   c1.push_back( 2 );
   c1.push_back( 3 );
   c2.push_back( 10 );
   c2.push_back( 20 );
   c3.push_back( 100 );

   cout << "The original deque c1 is:";
   for ( c1_Iter = c1.begin( ); c1_Iter != c1.end( ); c1_Iter++ )
      cout << " " << *c1_Iter;
   cout << endl;

   c1.swap( c2 );

   cout << "After swapping with c2, deque c1 is:";
   for ( c1_Iter = c1.begin( ); c1_Iter != c1.end( ); c1_Iter++ )
      cout << " " << *c1_Iter;
   cout << endl;

   swap( c1,c3 );

   cout << "After swapping with c3, deque c1 is:";
   for ( c1_Iter = c1.begin( ); c1_Iter != c1.end( ); c1_Iter++ )
      cout << " " << *c1_Iter;
   cout << endl;

   swap<>(c1, c2);
   cout << "After swapping with c2, deque c1 is:";
   for ( c1_Iter = c1.begin( ); c1_Iter != c1.end( ); c1_Iter++ )
      cout << " " << *c1_Iter;
   cout << endl;
}
  

需求

標頭: <deque>

命名空間: std

請參閱

參考

deque 類別

deque::assign 和 deque::swap

標準樣板程式庫