当前位置:网站首页>45.【list链表的应用】
45.【list链表的应用】
2022-07-30 23:32:00 【李在奋斗……】
【头部插入一个数据】
函数名.push_front()
【尾部插入一个数据】
函数名.push_back()
【多元插入数据】
函数名.insert(函数名.begin(),n) 从哪开始 插入谁
【多元插入数据2】
函数名.insert(函数名.begin(),n,m) 从哪开始 插入几个 插入谁
【利用迭代器插入】
iist〈函数类型〉 ::iterator 对象名;
对象名=函数名.begin();
函数名.insert(对象名,个数,元素)
【删除头一个元素】
函数名.pop_front()
【删除最后一个元素】
函数名.pop_back()
【多元删除数据】
函数名1.erase(函数名1.begin(),函数名1.end()
【链表遍历只能是迭代器遍历】
iist〈函数类型〉 ::iterator 对象名;
for(对象名=函数名.begin();对象名!=end();对象名++)
{
cout<<*对象名;
}
#include <list>
#include <iostream>
using namespace std;
int main()
{
list<int> list_a; //初始化为0
int s[4] = { 2,5,8 };
list<int> list_b(s, s + sizeof(s)/sizeof(int)); //普通数组复制给链表
list_b.push_front(1); //在头部插入
list_b.push_back(2); //在尾部插入
list_b.insert(list_b.begin(), 66); // 从哪插入, 插入什么
list_b.insert(list_b.end(), 88);
list_b.insert(list_b.end(),3, 100); // 从哪插入, 插入几个,插入谁
list<int>::iterator it; //利用迭代器锦新插入
it = list_b.begin();
it++;
list_b.insert(it, 5, 111);
list_b.insert(list_b.begin(), s, s + sizeof(s) / sizeof(int)); //插入普通数组
list_b.pop_front(); //删除头部一个
list_b.pop_back(); //删除尾部一个
//list_b.erase(list_b.begin(), list_b.end()); // 从头到位删除
list<int>::iterator itor;
for (itor = list_b.begin(); itor!= list_b.end(); itor++)
{
cout << *itor << " ";
}
return 0;
}


边栏推荐
- uniapp folding box secondary loop
- 一文详解:SRv6 Policy模型、算路及引流
- EasyExcel comprehensive course combat
- PS Basic Learning (1)
- leetcode(刷题篇13)
- Week 19 Progress (Understanding IoT Basics)
- Debezium报错系列之二十:task failed to create new topic.Ensure that the task is authorized to create topics
- Abstract classes and interfaces (study notes)
- 递增三元组
- [SAM template question] P3975 [TJOI2015] string theory
猜你喜欢

ctfshow 文件包含

【LeetCode】70. 爬楼梯 - Go 语言题解

Excel basic study notes

【LeetCode】42. 接雨水 - Go 语言题解

Manually set transaction commit in mysql

uniapp开发微信小程序-软考刷题小程序

$\text{ARC 145}$

C# VSCode & Rider引用命名空间快捷键

Apache Doris series: detailed steps for installation and deployment

Apache Doris series: In-depth understanding of real-time analytical database Apache Doris
随机推荐
JS中? ?和??=和?.和 ||的区别
Detailed operator
Manually set transaction commit in mysql
uni-ui安装
动态修改el-tab-pane 的label(整理)
Debezium报错系列之二十:task failed to create new topic.Ensure that the task is authorized to create topics
Day016 类和对象
2021GDCPC Guangdong University Student Programming Competition B.Byfibonacci
oracle数据库版本问题咨询(就是对比从数据库查询出来的版本,和docker里面的oracle版本)?
Android安全性优化——APP加固
Chevrolet Trailblazer, the first choice for safety and warmth for your family travel
ZZULIOJ:1119: sequence order
可视化工具Netron介绍
#yyds干货盘点# 面试必刷TOP101:判断链表中是否有环
"Wei cup" school more than 2022 cattle summer camp 4 L.B lack Hole, computational geometry
软件测试三阶段,你在哪一步?
Week 19 Progress (Understanding IoT Basics)
[0x800706D9] solution appears in Microsoft Store
win10重建索引
2022牛客暑期多校训练营1 J Serval and Essay