How to Traverse a List with reverse_iterator in C++? Last Updated : 22 Mar, 2024 Summarize Comments Improve Suggest changes Share Like Article Like Report In C++, lists are containers that allow users to store data in non-contiguous memory locations. List provides reverse iterators that make it easy to traverse the list in reverse order. In this article, we will learn how to traverse a list with reverse_iterator in C++. Example Input: myList = {10,20,30,40,50} Output: 50 40 30 20 10Iteratore a List with reverse_iterator in C++Reverse iterators in C++ are used to traverse the list in a backward direction starting from the end of the list towards the beginning. The std::list class template has two member functions that provide the reverse iterators: list::rbegin(): Returns the reverse iterator pointing to the last element in the list.list::rend(): Returns a reverse iterator pointing to the element just before the first element in the list.C++ Program to Traverse a List with reverse_iteratorThe following program illustrates how we can traverse a list using a reverse_iterator in C++: C++ // C++ Program to illustrate how to traverse a list with // reverse_iterator #include <iostream> #include <list> using namespace std; int main() { // Initializing a List list<int> l = { 10, 20, 30, 40, 50 }; // Declare the reverse iterator of the list list<int>::reverse_iterator it; // Traverse the elements of the list using the // reverse_iterator for (it = l.rbegin(); it != l.rend(); it++) { cout << *it << " "; } return 0; } Output50 40 30 20 10 Time Complexity: O(N) where N is the size of the list.Auxiliary Space: O(1) Comment More infoAdvertise with us Next Article How to Use a reverse_Iterator with a Map in C++? S sravankumar_171fa07058 Follow Improve Article Tags : C++ Programs C++ cpp-iterator cpp-list CPP Examples +1 More Practice Tags : CPP Similar Reads How to Traverse a Set with reverse_iterator in C++? In C++, sets are a type of associative container in which each element has to be unique because the value of the element identifies it. It provides reverse iterators that make it easier to traverse the set in reverse direction. In this article, we will discuss how to traverse a set with reverse_iter 2 min read How to Traverse a List with const_iterator in C++? In C++, a list is a container used to store data in non-contiguous memory locations. It also provides a constant iterator that provides the constant reference to its elements. In this article, we will discuss how to traverse a list with const_iterator in C++. Example Input: myList = {10,20,30,40,50} 2 min read How to Use a reverse_Iterator with a Map in C++? In C++, a reverse_iterator is a type of iterator that points to elements in a container in the reverse order. This means that using a reverse_iterator, you can traverse a container from end to beginning. In this article, we will learn how to use a reverse_iterator with a map in C++. Example: Input: 2 min read How to Traverse a Set with const_iterator in C++? In C++, sets are a type of associative container in which each element has to be unique because the value of the element identifies it. It contains a constant iterator that provides the constant reference to its elements. In this article, we will discuss how to traverse a set with const_iterator in 2 min read How to Traverse Vector Using const_reverse_iterator in C++? In C++, a vector can be traversed in reverse order using a const_reverse_iterator. A const_reverse_iterator is a type of iterator that points to the last element in the container and moves in the reverse direction. In this article, we will learn how to traverse a vector using a const_reverse_iterato 2 min read How to Use Iterator with a Vector in C++? In C++, vectors are the same as dynamic arrays with the ability to resize themselves automatically when an element is inserted or deleted. An iterator is a pointer-like object that can be used to access elements of a container (like an array or a vector). In this article, we will learn how to use an 2 min read Like