VOOZH about

URL: https://www.geeksforgeeks.org/cpp/forward_listreverse-in-c-stl/

⇱ forward_list::reverse() in C++ STL - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

forward_list::reverse() in C++ STL

Last Updated : 30 Jun, 2023

std::forward_list::reverse() is an inbuilt function in CPP STL which reverses the order of the elements present in the forward_list.

Syntax:

forwardlist_name.reverse()

Parameter: The function does not accept any parameter.

Return value: The function has no return value. It reverses the forward list.

Below program demonstrates the above function:

Program 1:


Output
List elements before performing reverse operation: 10 20 40 30 70 
List elements after performing reverse operation: 70 30 40 20 10

 Time Complexity: O(n)

Auxiliary Space: O(n)

Comment
Article Tags: