list::merge
Usuwa elementy z listy argumentów, wstawia je na liście cel oraz zamówienia nowe, połączone zestaw elementów w kolejności rosnącej lub w podanej kolejności.
void merge( list<Type, Allocator>& _Right ); template<class Traits> void merge( list<Type, Allocator>& _Right, Traits _Comp );
Parametry
_Right
Lista argumentów do scalenia z listy docelowej._Comp
Operator porównania porządkowania elementów na liście.
Uwagi
Lista argumentów _Right jest scalany z listy docelowej.
Wyświetla zarówno argument i docelowy musi zostać określona z tych samych relacji porównanie, według której jest wynikowe sekwencji, może zostać określona.Domyślna kolejność dla funkcji pierwszego elementu członkowskiego jest rosnącą.Druga funkcja elementu członkowskiego nakłada operacji porównywania określony przez użytkownika _Comp klasy cechy.
Przykład
// 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;
}
Wymagania
Nagłówek: < listy >
Przestrzeń nazw: std