C++ list reverse() Function
Example
Reverse the order of a list:
list<string> cars = {"Volvo", "BMW", "Ford", "Mazda"};
cars.reverse();
for (string car : cars) {
cout << car << "\n";
}
Definition and Usage
The reverse() function reverses the order of the elements in a list. The first element becomes the last, and the last element becomes the first.
The reverse function is defined in the <list> header file.
Syntax
list.reverse();
Parameter Values
None.
Technical Details
| Returns: | Nothing (void). |
|---|
Related Pages
Read more about lists in our List Tutorial.