在C++ STL中的函数

这个 deque::rend() 是C++中的一个内置函数,它返回一个 反向迭代器 指向德克开始之前的位置(被认为是它的反面)。

null

语法:

deque_name.rend()

参数: 此函数不接受任何参数。

返回值: 它返回一个 反向迭代器 它指向德克开始之前的位置。

下面的程序说明了上述功能:

项目1:

// C++ program to illustrate the
// deque::rend() function
#include <bits/stdc++.h>
using namespace std;
int main()
{
deque< int > dq = { 10, 20, 30, 40, 50 };
cout << "The deque in reverse order: " ;
// prints the elements in reverse order
for ( auto it = dq.rbegin(); it != dq.rend(); ++it)
cout << *it << " " ;
return 0;
}


输出:

The deque in reverse order: 50 40 30 20 10

项目2:

// C++ program to illustrate the
// deque::rend() function
#include <bits/stdc++.h>
using namespace std;
int main()
{
deque< char > dq = { 'a' , 'b' , 'c' , 'd' , 'e' };
cout << "The deque in reverse order: " ;
// prints the elements in reverse order
for ( auto it = dq.rbegin(); it != dq.rend(); ++it)
cout << *it << " " ;
return 0;
}


输出:

The deque in reverse order: e d c b a

© 版权声明
THE END
喜欢就支持一下吧
点赞8 分享