list rbegin() and rend() function in C++ STL
- list::rbegin() is an inbuilt function in C++ STL that returns a reverse iterator which points to the last element of the list.
Syntax:
list_name.rbegin()
Parameter: This function does not accept any parameters.
Return value: It returns a reverse iterator which points to the last element of the list.
Below program illustrates the above function:
// C++ program to illustrate the// list::rbegin() function#include <bits/stdc++.h>usingnamespacestd;intmain(){list<int> lis = { 10, 20, 30, 40, 50 };cout <<"The list in reverse order: ";for(autoit = lis.rbegin(); it != lis.rend(); ++it)cout << *it <<" ";return0;}chevron_rightfilter_noneOutput:The list in reverse order: 50 40 30 20 10
- list::rend() is an inbuilt function in C++ STL that returns a reverse iterator which points to the position before the beginning of the list.
Syntax:
list_name.rend()
Parameter: The function does not accept any parameters.
Return value: It returns a reverse iterator which points to the position before the beginning of the list.
Below program illustrates the above function:
// C++ program to illustrate the// list::rbegin() function#include <bits/stdc++.h>usingnamespacestd;intmain(){list<int> lis = { 10, 20, 30, 40, 50 };cout <<"The list in reverse order: ";for(autoit = lis.rbegin(); it != lis.rend(); ++it)cout << *it <<" ";return0;}chevron_rightfilter_noneOutput:The list in reverse order: 50 40 30 20 10
Recommended Posts:
- multiset rbegin() and rend() function in C++ STL
- vector rbegin() and rend() function in C++ STL
- set::rbegin() and set::rend() in C++ STL
- array::rbegin() and array::rend() in C++ STL
- map rend() function in C++ STL
- map rbegin() function in C++ STL
- map rbegin() function in C++ STL
- deque rend() function in C++ STL
- deque rbegin() function in C++ STL
- multimap rend in C++ STL
- multimap rbegin in C++ STL
- list end() function in C++ STL
- list assign() function in C++ STL
- list resize() function in C++ STL
- list push_back() function in C++ STL
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



