std::forward_list<T,Allocator>:: reverse
From cppreference.net
<
cpp
|
container
|
forward list
C++
Containers library
|
(C++17)
|
||||
| Sequence | ||||
|
(C++11)
|
||||
|
(C++26)
|
||||
|
(C++26)
|
||||
|
(C++11)
|
||||
| Associative | ||||
| Unordered associative | ||||
|
(C++11)
|
||||
|
(C++11)
|
||||
|
(C++11)
|
||||
|
(C++11)
|
||||
| Adaptors | ||||
|
(C++23)
|
||||
|
(C++23)
|
||||
|
(C++23)
|
||||
|
(C++23)
|
||||
| Views | ||||
|
(C++20)
|
||||
|
(C++23)
|
||||
| Tables | ||||
| Iterator invalidation | ||||
| Member function table | ||||
| Non-member function table |
std::forward_list
| Member functions | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Non-member functions | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Deduction guides (C++17) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
void
reverse
(
)
noexcept
;
|
(自 C++11 起)
(自 C++26 起为 constexpr) |
|
反转容器中元素的顺序。
不会使任何引用或迭代器失效。
复杂度
与容器大小呈线性关系。
示例
运行此代码
#include <iostream> #include <forward_list> std::ostream& operator<<(std::ostream& ostr, const std::forward_list<int>& list) { for (auto& i : list) ostr << ' ' << i; return ostr; } int main() { std::forward_list<int> list = {8, 7, 5, 9, 0, 1, 3, 2, 6, 4}; std::cout << "初始状态: " << list << '\n'; list.sort(); std::cout << "升序排列: " << list << '\n'; list.reverse(); std::cout << "降序排列:" << list << '\n'; }
输出:
初始状态: 8 7 5 9 0 1 3 2 6 4 升序排列: 0 1 2 3 4 5 6 7 8 9 降序排列: 9 8 7 6 5 4 3 2 1 0
参见
|
对元素进行排序
(公开成员函数) |