Aracılığıyla paylaş


list::merge

Öğe bağımsız değişken listesi'nden kaldırır, hedef listesine ekler ve yeni, birleşik kümesi öğeleri artan sırada veya başka bir belirtilen sipariş, sipariş.

void merge(
   list<Type, Allocator>& _Right
);
template<class Traits>
   void merge(
      list<Type, Allocator>& _Right, 
      Traits _Comp
   );

Parametreler

  • _Right
    Hedef listesi ile birleştirilecek bağımsız değişken listesi.

  • _Comp
    Hedef liste öğeleri sipariş etmek için kullanılan karşılaştırma işleci.

Notlar

Bağımsız değişken listesi _Right hedef listesi ile birleştirdi.

Bağımsız değişken ve hedef listeleri karşılaştırma aynı ilişkisi tarafından elde edilen sıra sipariþ edilmesi olduğu sipariş edilebilir.Varsayılan sipariş ilk üye işlev için artan sırada.Kullanıcı tarafından belirtilen karşılaştırma işlemi ikinci üye işlevi uygular _Comp sınıfı nitelikler.

Örnek

// list_merge.cpp
// compile with: /EHsc
#include <list>
#include <iostream>

int main( ) 
{
   using namespace std;
   list <int> c1, c2, c3;
   list <int>::iterator c1_Iter, c2_Iter, c3_Iter;
   
   c1.push_back( 3 );
   c1.push_back( 6 );
   c2.push_back( 2 );
   c2.push_back( 4 );
   c3.push_back( 5 );
   c3.push_back( 1 );

   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;

   c2.merge( c1 );  // Merge c1 into c2 in (default) ascending order
   c2.sort( greater<int>( ) );
   cout << "After merging c1 with c2 and sorting with >: c2 =";
   for ( c2_Iter = c2.begin( ); c2_Iter != c2.end( ); c2_Iter++ )
      cout << " " << *c2_Iter;
   cout << endl;

   cout << "c3 =";
   for ( c3_Iter = c3.begin( ); c3_Iter != c3.end( ); c3_Iter++ )
      cout << " " << *c3_Iter;
   cout << endl;

   c2.merge( c3, greater<int>( ) );
   cout << "After merging c3 with c2 according to the '>' comparison relation: c2 =";
   for ( c2_Iter = c2.begin( ); c2_Iter != c2.end( ); c2_Iter++ )
      cout << " " << *c2_Iter;
   cout << endl;
}
  

Gereksinimler

Başlık: <list>

Namespace: std

Ayrıca bkz.

Başvuru

list Class

Standart Şablon Kütüphanesi