std::list<T,Allocator>::reverse
來自 cppreference.com
void reverse(); |
(C++11 起無異常丟擲) | |
反轉容器中元素的順序。所有引用或迭代器都保持有效。
目錄 |
[編輯] 引數
(無)
[編輯] 返回值
(無)
[編輯] 複雜度
與容器大小成線性關係。
[編輯] 示例
執行此程式碼
#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 << "initially: " << list << '\n'; list.sort(); std::cout << "ascending: " << list << '\n'; list.reverse(); std::cout << "descending:" << list << '\n'; }
輸出
initially: 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
缺陷報告
下列更改行為的缺陷報告追溯地應用於以前出版的 C++ 標準。
缺陷報告 | 應用於 | 釋出時的行為 | 正確的行為 |
---|---|---|---|
LWG 1207 | C++98 | 迭代器和/或引用是否會失效不明確 | 保持有效 |
[編輯] 另請參閱
排序元素 (公有成員函式) |