记下笔记:
来源:https://www.bilibili.com/video/BV1et411b73Z?p=211
list容器 的 构造函数
list容器 的 赋值和交换
list容器 的 大小操作
list容器 的 插入和删除
感觉有点长 还是 复制一下
void printList(const list& L)
{
for (list::const_iterator it = L.begin(); it != L.end(); it++)
{
cout << *it<<" ";
}
cout << endl;
}
void test05()
{
//插入数据
list L1;
L1.push_back(10);
L1.push_back(20);
L1.push_back(30);
L1.push_front(100);
L1.push_front(200);
L1.push_front(300);
printList(L1);
//删除数据
L1.pop_back();
L1.pop_front();
printList(L1);
//数据插入
list<int>::iterator it = L1.begin();
L1.insert(++it, 1000);
printList(L1);
//数据删除
it = L1.begin();
L1.erase(++it);
printList(L1);
//数据移除
L1.resize(10, 10000);
printList(L1);
L1.remove(10000);
printList(L1);
//数据清空
L1.clear();
printList(L1);
}
list容器 的 数据存取
真想访问就定义一个迭代器 然后迭代器++ *迭代器。