目录

forward_list::erase_after

描述 (Description)

C ++函数std::forward_list::erase_after()std::forward_list::erase_after()删除位置之后的单个元素,并将其大小减小一。

声明 (Declaration)

以下是std :: forward_list :: erase_after()函数形式std :: forward_list头的声明。

C++11

iterator erase_after (const_iterator position);

参数 (Parameters)

position - 迭代器到列表元素。

返回值

返回一个随机访问迭代器,它指向从中删除元素的位置。

异常 (Exceptions)

如果position无效,则行为未定义。

时间复杂

线性即O(n)

例子 (Example)

以下示例显示了std :: forward_list :: erase_after()函数的用法。

#include <iostream>
#include <forward_list>
using namespace std;
int main(void) {
   forward_list<int> fl = {1, 1000, 2, 3, 4, 5};
   fl.erase_after(fl.begin());
   cout << "List contains following elements" << endl;
   for (auto it = fl.begin(); it != fl.end(); ++it)
      cout << *it << endl;
   return 0;
}

让我们编译并运行上面的程序,这将产生以下结果 -

List contains following elements
1
2
3
4
5
↑回到顶部↑
WIKI教程 @2018