list rbegin() and rend() function in C++ STL - GeeksforGeeks

17 Jul, 2018
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>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;}Output: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>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;}Output:The list in reverse order: 50 40 30 20 10

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>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;}Output:The list in reverse order: 50 40 30 20 10

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>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

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>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;}Output:The list in reverse order: 50 40 30 20 10

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>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

CPP-Functions
cpp-list
STL
C++
STL
CPP
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Operator Overloading in C++
Polymorphism in C++
Sorting a vector in C++
Friend class and function in C++
std::string class in C++
Pair in C++ Standard Template Library (STL)
Queue in C++ Standard Template Library (STL)
Inline Functions in C++
Array of Strings in C++ (5 Different Ways to Create)
Convert string to char array in C++