fork download
  1. #include<iostream>
  2. #include<list>
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7. // Creating a list
  8. list<int> List1;
  9.  
  10. // Adding elements to the list
  11. List1.push_back(1);
  12. List1.push_back(2);
  13. List1.push_back(3);
  14.  
  15. // Initial list:
  16. cout << "List Initial: ";
  17. for (auto itr = List1.begin(); itr != List1.end(); itr++)
  18. cout << *itr << " ";
  19.  
  20. // reversing the list
  21. List1.reverse();
  22.  
  23. // List after reversing the order of elements
  24. cout << "\n\nList after reversing: ";
  25. for (auto itr = List1.begin(); itr != List1.end(); itr++)
  26. cout << *itr << " ";
  27.  
  28. return 0;
  29. }
Success #stdin #stdout 0s 4376KB
stdin
Standard input is empty
stdout
List Initial: 1 2 3 

List after reversing: 3 2 1