forward_list::splice_after
描述 (Description)
C ++函数std::forward_list::splice_after()将迭代器i指向的元素从forward_list x传递到* this 。 元素在位置指向的元素之后插入。
声明 (Declaration)
以下是std :: forward_list :: splice_after()函数形式std :: forward_list头的声明。
C++11
void splice_after (const_iterator position, forward_list& x, const_iterator i);
参数 (Parameters)
position - 在forward_list中的位置,之后要插入新元素。
x - 相同类型的另一个forward_list对象。
i - 随机访问迭代器。
返回值
没有
异常 (Exceptions)
该成员函数从不抛出异常。
时间复杂
线性即O(n)
例子 (Example)
以下示例显示了std :: forward_list :: splice_after()函数的用法。
#include <iostream>
#include <forward_list>
using namespace std;
int main(void) {
forward_list<int> fl1 = {1, 2};
forward_list<int> fl2 = {1, 3, 4, 5};
fl2.splice_after(fl2.begin(), fl1, fl1.begin());
cout << "List contains following elements" << endl;
for (auto it = fl2.begin(); it != fl2.end(); ++it)
cout << *it << endl;
return 0;
}
让我们编译并运行上面的程序,这将产生以下结果 -
List contains following elements
1
2
3
4
5