什么是C ++中的双端队列back()?

阅读 152 收藏 0 点赞 0 评论 0

双端队列back()函数用于引用双端队列的最后一个元素。

语法

dequename.back( )

示例

输入双端队列-11 12 13 14 15

输出新双端输出-15

输入双端队列-选择

输出新双端队列-E

可以遵循的方法

  • 首先我们宣布双端队列

  • 然后我们打印双端队列。

  • 然后我们定义back()函数。

通过使用上述方法,我们可以获取双端队列的最后一个元素。

示例

// C++ code to demonstrate the working of deque back( ) function
#include<iostream.h>
#include<deque.h>
Using namespace std;
int main( ){
   //初始化双端队列
   deque<int> deque ={ 14, 15, 16, 17, 18 };
   cout<< “ Deque: “;
   for( auto x = deque.begin( ); x != deque.end( ); ++x)
      cout<< *x << “ “;
   //定义back()函数
   cout<< deque.back( );
   return 0;
}

输出结果

如果我们运行上面的代码,那么它将生成以下输出

Input: 14 15 16 17 18
Output: 18
Input: S A L T
Output: T
评论列表


问题


面经


文章

微信
公众号

扫码关注公众号