C++ Deque 库 - end() 函数


描述

C++ 函数std::deque::end()返回一个随机访问迭代器,该迭代器指向双端队列的最后一个元素。

宣言

以下是 std::deque::end() 函数形式 std::deque 标头的声明。

C++98

iterator end();
const_iterator end() const;

C++11

iterator end() noexcept;
const_iterator end() const noexcept;

参数

没有任何

返回值

如果 deque 对象是常量限定的,则方法返回常量随机访问迭代器,否则返回非常量随机访问迭代器。

例外情况

该成员函数从不抛出异常。

时间复杂度

常数即 O(1)

例子

以下示例显示了 std::deque::end() 函数的用法。

#include <iostream>
#include <deque>

using namespace std;

int main(void) {

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

   cout << "Contents of deque in reverse order" << endl;

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

   return 0;
}

让我们编译并运行上面的程序,这将产生以下结果 -

Contents of deque in reverse order
5
4
3
2
1
双端队列.htm