algorithm(最大最小操作)

max(a, b, comp) 返回两个元素中值最大的元素,可以自定谓词
result = max(3, 7);//7
max_element(a, b, comp) 返回给定范围中值最大的元素

	int ar[11] = { 1, 3, 5, 7, 9, 10, 0, 2, 4, 6, 8};

	int *result;
	result = max_element(ar,ar+11,Ifbigger);//Ifbigger 前者大于后者时,返回1  最后结果0 找min

min 返回两个元素中值最小的元素
min_element 返回给定范围中值最小的元素
minmax C++11 返回两个元素中值最大及最小的元素

	pairresult_1;
	result_1 = minmax(3, 8);
	cout << result_1.first << result_1.second << endl;//3 8

minmax_element C++11 返回给定范围中值最大及最小的元素

	int ar[11] = { 1, 3, 5, 7, 9, 10, 0, 2, 4, 6, 8};

	pairresult;
	result = minmax_element(ar,ar+11);//Ifbigger 前者大于后者时,返回1  最后结果0 找min
	cout << *result.first << "\t"<<*result.second<

is_permutation(f1,l1,f2,pred) C++11 判断一个序列是否是另一个序列的一种排序,第二个序列为f2到与f1-l1的范围一致。pred二元谓词(Binary)函数,以两个元素为参数,然后返回一个可转换成 bool 类型的值。其返回值表明指定两个元素是否满足当前函数所检测的匹配条件。

namespace ClassFoo{
    bool IfEqual(int m, int n) {
        return (m == n);
    }
    void IsPermutation_1() {
        CLASSFOO_VECTOR(int, BigVector, { 8, 23, 5, 6, 7, 29, 0, 5, 6, 7, 1, 1 });
        CLASSFOO_VECTOR(int, SmallVector, { 23, 5, 8, 6, 7, 29, 0, 7, 6, 5, 1, 1 });
        // 等价比较
        bool b = std::is_permutation(
            std::begin(BigVector),
            std::end(BigVector),
            std::begin(SmallVector));
        if (b) {
            std::cout << "相等" << '\n';
        }
        // 自定谓词比较
        b = std::is_permutation(
            std::begin(BigVector),
            std::end(BigVector),
            std::begin(SmallVector),
            IfEqual);
        if (b) {
            std::cout << "相等" << '\n';
        }
    }
}
int main()
{
    ClassFoo::IsPermutation_1();
    return 0;
}
相等
相等

lexicographical_compare 比较两个序列的字典序,
如果第一个范围以字典序(Lexicographically)相比小于第二个,则返回 true。

在这里插入代码片

next_permutation(f1,l1,f2,l2,comp) 返回给定范围中的元素组成的下一个按字典序的排列
prev_permutation 返回给定范围中的元素组成的上一个按字典序的排列

你可能感兴趣的:(STL)