C++ List 库 - crend() 函数
描述
C++ 函数 std::list::crend() 返回一个常量反向迭代器,它指向列表中第一个元素之前的理论元素,即列表的反向结尾。
声明
以下是 std::list::crend() 函数形式 std::list 头的声明。
C++11
const_reverse_iterator crend() const noexcept;
参数
None
返回值
返回一个常量随机反向迭代器,它指向列表的反向端。
异常
此成员函数从不抛出异常。
时间复杂度
常数,即 O(1)
示例
以下示例显示了 std::list::crend() 函数的用法。
#include <iostream>
#include <list>
using namespace std;
int main(void) {
list<int> l = {1, 2, 3, 4, 5};
cout << "List contains following element in reverse order" << endl;
for (auto it = l.crbegin(); it != l.crend(); ++it)
cout << *it << endl;
return 0;
}
让我们编译并运行上面的程序,这将产生以下结果 −
List contains following element in reverse order 5 4 3 2 1

