C++ List 库 - push_back() 函数
描述
C++ 函数 std::list::push_back() 在列表末尾插入新元素并将列表大小增加一。
声明
以下是 std::list::push_back() 函数形式 std::list 头的声明。
C++11
void push_back (value_type&& val);
参数
val − 要插入到列表中的元素的值。
返回值
None.
异常
此成员函数从不抛出异常。
时间复杂度
常数,即 O(1)
示例
以下示例显示了 std::list::push_back() 函数的用法。
#include <iostream>
#include <list>
using namespace std;
int main(void) {
list<int> l1 = {1, 2, 3, 4, 5};
list<int> l2;
for (auto it = l1.begin(); it != l1.end(); ++it)
l2.push_back(move(*it));
cout << "List l2 contains following elements" << endl;
for (auto it = l2.begin(); it != l2.end(); ++it)
cout << *it << endl;
return 0;
}
让我们编译并运行上面的程序,这将产生以下结果 −
List l2 contains following elements 1 2 3 4 5

