STL_merge

//

STL_merge

头文件
#include<algorithm>

01 数组 merge( a,a+a_size,b,b+b_size,c,cmp );
02 容器 merge( c1.begin(),c1.end(),c2.begin(),c2.begin(),ans.begin(),cmp );

attention: 

    01 原序列必须先有序
    02 cmp 可缺省 默认为升序
    03 cmp 排序规则 必须和 原序列规则 相同 !!!

// eg.
#include<bits/stdc++.h>
using namespace std;

int main()
{
    int a[5]={ 9,7,5,3,1 };
    int b[5]={ 8,6,4,2,0 };
    int c[11];
    merge( a,a+5,b,b+5,c,greater<int>() );

    for( int i=0;i<10;i++ )
    {
        if( i ) cout<<' ';
        cout<<c[i];
    }
    cout<<endl;

    return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_63173957/article/details/123579228
STL