C++ 雙端佇列庫 - crend() 函式



描述

C++ 函式std::deque::crend()返回一個常量反向迭代器,它指向雙端佇列中理論上第一個元素之前的元素,即雙端佇列的反向末尾。

宣告

以下是來自std::deque 標頭檔案的 std::deque::crend() 函式宣告。

C++11

const_reverse_iterator crend() const noexcept;

引數

返回值

返回一個指向雙端佇列反向末尾的常量隨機反向迭代器。

異常

此成員函式從不丟擲異常。

時間複雜度

常數,即 O(1)

示例

以下示例演示了 std::deque::crend() 函式的用法。

#include <iostream>
#include <deque>

using namespace std;

int main(void) {

   deque<int> d = {1, 2, 3, 4, 5};

   cout << "Contents of deque are" << endl;

   for (auto it = d.crend() - 1; it >= d.crbegin(); --it)
      cout << *it << endl;

   return 0;
}

讓我們編譯並執行上述程式,這將產生以下結果:

Contents of deque are
1
2
3
4
5
deque.htm
廣告