std::list::reverse
STD::List::反向
void reverse( | | |
---|
反转容器中元素的顺序。没有引用或迭代器失效。
参数
%280%29
返回值
%280%29
例外
(none) | (until C++11) |
---|---|
noexcept specification: noexcept | (since 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 << "before: " << list << "\n";
list.sort(
std::cout << "ascending: " << list << "\n";
list.reverse(
std::cout << "descending: " << list << "\n";
}
二次
产出:
二次
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
二次
另见
sort | sorts the elements (public member function) |
---|
© cppreference.com
在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。