Skip to content
This repository has been archived by the owner on Nov 8, 2023. It is now read-only.

Latest commit

 

History

History
40 lines (30 loc) · 865 Bytes

reverse.md

File metadata and controls

40 lines (30 loc) · 865 Bytes

reverse

Description : The list::reverse() is used to reverse the order of the list.

Example:

#include<iostream>
#include<list> 
using namespace std; 
  
int main() 
{ 
    // Creating a list 
    list<int> List1; 
  
    // Adding elements to the list 
    List1.push_back(1); 
    List1.push_back(2); 
    List1.push_back(3);  
  
    // Initial list: 
    cout << "List Initial: "; 
    for (auto itr = List1.begin(); itr != List1.end(); itr++) 
        cout << *itr << " "; 
  
    // reversing the list 
    List1.reverse(); 
  
    // List after reversing the order of elements 
    cout << "\n\nList after reversing: "; 
    for (auto itr = List1.begin(); itr != List1.end(); itr++) 
        cout << *itr << " "; 
  
    return 0; 
} 
    

See Sample Code Run Code