C++ STL中的多集CRORKEN()和CREDENE()函数

这个 多集::crbegin() 是C++ STL中的一个内置函数,它返回指向容器中最后一个元素的常数反向迭代器。迭代器不能用于修改multiset容器中的元素。迭代器可以相应地增加或减少以遍历集合。

null

语法:

constant_reverse_iterator multiset_name.crbegin()

参数: 该函数不接受任何参数。

返回值: 该函数返回指向容器中最后一个元素的常量迭代器。

下面的程序演示了multiset::crbegin()方法。

C++

// C++ program to demonstrate the
// multiset::crbegin() function
#include <bits/stdc++.h>
using namespace std;
int main()
{
int arr[] = { 14, 10, 15, 11, 10 };
// initializes the set from an array
multiset< int > s(arr, arr + 5);
cout << "The last element: " << *(s.crbegin()) << endl;
// prints all elements in set
for ( auto it = s.crbegin(); it != s.crend(); it++)
cout << *it << " " ;
return 0;
}


输出:

The last element: 1515 14 11 10 10

这个 多集::crend() 在C++ STL中是一个内置函数,它返回一个常数反向迭代器,指向容器前第一个元素之前的位置。迭代器不能用于修改multiset容器中的元素。迭代器可以相应地增加或减少以遍历集合。

语法:

constant_reverse_iterator multiset_name.crend()

参数: 该函数不接受任何参数。

返回值: 该函数返回一个常量迭代器,该迭代器指向multiset容器中第一个元素之前的位置。

下面的程序演示了multiset::crend()方法。

C++

// C++ program to demonstrate the
// multiset::crend() function
#include <bits/stdc++.h>
using namespace std;
int main()
{
int arr[] = { 14, 12, 15, 11, 10, 10, 16, 16 };
// initializes the set from an array
multiset< int > s(arr, arr + 8);
// prints all elements in set
for ( auto it = s.crbegin(); it != s.crend(); it++)
cout << *it << " " ;
return 0;
}


输出:

16 16 15 14 12 11 10 10

© 版权声明
THE END
喜欢就支持一下吧
点赞15 分享