目录

deque::back

描述 (Description)

C ++函数std::deque::back()返回对双端队列的最后一个元素的引用。 将此函数调用为空会导致未定义的行为。

声明 (Declaration)

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

C++98

reference back();
const_reference back() const;

参数 (Parameters)

没有

返回值

返回对最后一个元素的引用。 如果deque对象是限定的,那么方法返回常量引用,否则返回非常量引用。

异常 (Exceptions)

在空时调用此方法会导致未定义的行为。

时间复杂

常数即O(1)

例子 (Example)

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

#include <iostream>
#include <deque>
using namespace std;
int main(void) {
   deque<int> d = {1, 2, 3, 4, 5};
   cout << "Last element of deque = " << d.back() << endl;
   return 0;
}

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

Last element of deque = 5
↑回到顶部↑
WIKI教程 @2018