list::merge
从中移除元素参数列表,它们添加到目标列表的插入和命令新元素,联合组件在升序或按其他一些指定的顺序。
void merge(
list<Type, Allocator>& _Right
);
template<class Traits>
void merge(
list<Type, Allocator>& _Right,
Traits _Comp
);
参数
_Right
参数列表与目标组合列表。_Comp
比较运算符用于对目标元素的列表。
备注
参数列表 _Right 与目标组合列表。
参数和目标列表必须顺序与所得的顺序排序的同一比较关系。 第一个成员函数的默认命令是升序。 第二个成员函数会选件类 Traits的用户指定的比较操作 _Comp。
示例
// 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;
}
要求
标头: <list>
命名空间: std