Home C&C++函数库 c++ 语法 程序源码 Linux C库

std::

list::reverse

公众成员函数  <list>
1)
void reverse();
(2)
void reverse() noexcept;

颠倒元素的顺序

反转列表容器中元素的顺序。

☲  参数


none

☉  返回值



none

☣  示例



// reversing list
#include <iostream>
#include <list>

int main ()
{
  std::list<int> mylist;

  for (int i=1; i<10; ++i) mylist.push_back(i);

  mylist.reverse();

  std::cout << "mylist contains:";
  for (std::list<int>::iterator it=mylist.begin(); it!=mylist.end(); ++it)
    std::cout << ' ' << *it;

  std::cout << '\n';

  return 0;
}

输出:
mylist contains: 9 8 7 6 5 4 3 2 1

✥ 复杂度



列表大小线性。

☣ 迭代器的有效性



不变

⇄ 数据竞争


容器修改。
不访问所包含的元素:并发访问或修改它们是安全的,遍历容器是不安全的。

☂ 异常安全性



No-throw保证:这个成员函数从不抛出异常。

🍄  另请参阅



list::splice 从另一个list转移元素(公众成员函数)
list::sort 对容器中的元素进行排序(公众成员函数)
list::swap 交换内容(公众成员函数)

联系我们 免责声明 关于CandCplus 网站地图