STL中C ++中的deque_rend()
给出的任务是显示C++STL中Dequerend()函数的功能
什么是双端队列?
双端队列是双端队列,它是序列容器,在两端都提供扩展和收缩功能。队列数据结构允许用户仅在END插入数据,并从FRONT删除数据。让我们以在公交车站排队的类比为例,那里的人只能从END插入队列,而站在FRONT的人是第一个被移走的人,而在双头队列中,可以同时插入和删除数据结束。
什么是rend()函数?
rend()函数返回一个反向迭代器,该迭代器指向双端队列容器中第一个元素之前的元素,rend()函数使双端队列反向。
语法 -deque_name.rend()
返回值 -返回一个反向迭代器,该迭代器指向双端队列的第一个元素之前的位置。
示例
输入双端队列-54420
输出反向双端输出-02445
输入双端 队列-整流器
输出反向双端队列-金色
可以遵循的方法
首先我们声明双端队列。
然后我们打印双端队列。
然后,我们使用rend()函数。
然后我们在反转操作之后打印新的双端队列。
通过使用上面的方法,我们可以获得反向双端队列
示例
// C++ code to demonstrate the working of deque rend( ) function
#include<iostream.h>
#include<deque.h>
Using namespace std;
int main ( ){
//初始化双端队列
Deque<int> deque = { 7, 4, 0, 3, 7 };
//打印双端队列
cout<< “ Deque: “;
for( auto x = deque.begin( ); x != deque.end( ); ++x)
cout<< *x << “ “;
//打印反向双端队列
cout<< “ Reversed deque: ”;
for( x = deque.rbegin( ) ; x != deque.rend( ); ++x)
cout<< “ “ <<*x;
return 0;
}输出结果
如果我们运行上面的代码,那么它将生成以下输出
Input - Deque: 7 4 0 3 7 Output - Reversed Deque: 7 3 0 4 7
示例
// C++ code to demonstrate the working of deque rend( ) function
#include<iostream.h>
#include<deque.h>
Using namespace std;
int main( ){
//初始化双端队列
deque<char> deque ={ ‘S’ , ‘U’ , ‘B’ , ‘T’ , ‘R’ , ‘A’ , ‘C’ , ‘T’ };
cout<< “ Deque: “;
for( auto x = deque.begin( ); x != deque.end( ); ++x)
cout<< *x << “ “;
//打印反向双端队列
cout<< “ Reversed deque:”;
for( x = deque.rbegin( ) ; x != deque.rend( ); ++x)
cout<< “ “ <<*x;
return 0;
}输出结果
如果我们运行上面的代码,那么它将生成以下输出
Input – Deque: S U B T R A C T Output – Reversed deque : T C A R T B U S