void reverse(); | (until C++11) | |
void reverse() noexcept; | (since C++11) |
Reverses the order of the elements in the container. No references or iterators become invalidated.
(none).
(none).
Linear in the size of the container.
#include <iostream> #include <list> std::ostream& operator<<(std::ostream& ostr, const std::list<int>& list) { for (auto &i : list) { ostr << " " << i; } return ostr; } int main() { std::list<int> list = { 8,7,5,9,0,1,3,2,6,4 }; std::cout << "before: " << list << "\n"; list.sort(); std::cout << "ascending: " << list << "\n"; list.reverse(); std::cout << "descending: " << list << "\n"; }
Output:
before: 8 7 5 9 0 1 3 2 6 4 ascending: 0 1 2 3 4 5 6 7 8 9 descending: 9 8 7 6 5 4 3 2 1 0
sorts the elements (public member function) |
© cppreference.com
Licensed under the Creative Commons Attribution-ShareAlike Unported License v3.0.
http://en.cppreference.com/w/cpp/container/list/reverse