- 列表::rbegin() 是C++ STL中的内置函数,它返回指向列表最后元素的反向迭代器。
语法:
list_name.rbegin()
参数: 此函数不接受任何参数。
返回值: 它返回一个反向迭代器,该迭代器指向列表的最后一个元素。
下面的程序说明了上述功能:
// C++ program to illustrate the
// list::rbegin() function
#include <bits/stdc++.h>
using
namespace
std;
int
main()
{
list<
int
> lis = { 10, 20, 30, 40, 50 };
cout <<
"The list in reverse order: "
;
for
(
auto
it = lis.rbegin(); it != lis.rend(); ++it)
cout << *it <<
" "
;
return
0;
}
输出:The list in reverse order: 50 40 30 20 10
- 列表::rend() 在C++ STL中是一个内置函数,它返回一个反向迭代器,指向列表开始之前的位置。
语法:
list_name.rend()
参数: 该函数不接受任何参数。
返回值: 它返回一个反向迭代器,该迭代器指向列表开头之前的位置。
下面的程序说明了上述功能:
// C++ program to illustrate the
// list::rbegin() function
#include <bits/stdc++.h>
using
namespace
std;
int
main()
{
list<
int
> lis = { 10, 20, 30, 40, 50 };
cout <<
"The list in reverse order: "
;
for
(
auto
it = lis.rbegin(); it != lis.rend(); ++it)
cout << *it <<
" "
;
return
0;
}
输出:The list in reverse order: 50 40 30 20 10
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END