Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

list reverse function in C++ STL

  • Difficulty Level : Basic
  • Last Updated : 25 Jun, 2018

The list::reverse() is a built-in function in C++ STL which is used to reverse a list container. It reverses the order of elements in the list container.


Want to learn from the best curated videos and practice problems, check out the C++ Foundation Course for Basic to Advanced C++ and C++ STL Course for foundation plus STL.  To complete your preparation from learning a language to DS Algo and many more,  please refer Complete Interview Preparation Course.

Parameters: This function does not accept any parameters.

Return Value: This function does not return any value. It just reverses the order of elements in the list container with which it is used.

Below program illustrate the list::reverse() function in C++ STL:

// CPP program to illustrate the
// list::reverse() function
#include <bits/stdc++.h>
using namespace std;
int main()
    // Creating a list
    list<int> demoList;
    // Adding elements to the list
    // Initial list:
    cout << "Initial List: ";
    for (auto itr = demoList.begin(); itr != demoList.end(); itr++)
        cout << *itr << " ";
    // reversing the list
    // List after reversing the order of elements
    cout << "\n\nList after reversing: ";
    for (auto itr = demoList.begin(); itr != demoList.end(); itr++)
        cout << *itr << " ";
    return 0;
Initial List: 10 20 30 40 

List after reversing: 40 30 20 10
My Personal Notes arrow_drop_up
Recommended Articles
Page :