当前位置: 首页 > news >正文

14-6-3C++STL的list

(一)list的插入

1.list.insert(pos,elem);//在pos位置插入一个elem元素的拷贝,返回新数据的位置

#include <iostream>
#include <list>
using namespace std;
int main()
{
    list<int> lst;
    lst.push_back(10);
    lst.push_back(30); 
    lst.push_back(40);
    list<int>::iterator it;
    it=lst.begin() ;
    it++;
    lst.insert(it,20);
    for(it=lst.begin();it!=lst.end();it++)
    {
        cout<<*it<<" ";
    }
    cout<<endl;
    return 0;
}

#include <iostream>
#include <list>
using namespace std;
int main()
{
    list<int> lst;
    lst.push_back(10);
    lst.push_back(30); 
    lst.push_back(50);
    list<int>::iterator it;
    for(it=lst.begin();it!=lst.end();it++)
    {
        if(*it==50)
        break;
    }
    if(it!=lst.end())
    {
        lst.insert(it,40);
    }
        for(it=lst.begin();it!=lst.end();it++)
    {
        cout<<*it<<" ";
    }
    cout<<endl;
    return 0;
}

2.list.insert(pos,n,elem);//在pos位置插入n个elem数据,无返回值

#include <iostream>
#include <list>
using namespace std;

int main()
{
    list<int> lst;
    lst.push_back(10);
    lst.push_back(30);
    lst.push_back(50);
    list<int>::iterator it = lst.end();
    lst.insert(it, 3, 70);
    for(it = lst.begin(); it != lst.end(); ++it)
    {
        cout << *it << " ";
    }
    cout << endl;

    return 0;
}

3.list.insert(pos,beg,end);//在pos位置插入[beg,end)区间的数据,无返回值

#include <iostream>
#include <list>
using namespace std;

int main()
{
    list<int> lst, lst1;
    lst.push_back(10);
    lst.push_back(30);
    lst.push_back(50);
    lst1.push_back(20);
    lst1.push_back(40);
    list<int>::iterator it;
    for(it = lst.begin(); it != lst.end(); ++it)
    {
        cout << *it << " ";
    }
    cout << endl;
    lst.insert(lst.end(), lst1.begin(), lst1.end());

    for(it = lst.begin(); it != lst.end(); ++it)
    {
        cout << *it << " ";
    }
    cout << endl;

    return 0;
}


(二)list的删除

1.list.clear(); //移除容器的所有数据

#include <iostream>
#include <list>
using namespace std;

int main()
{
    list<int> lst, lst1;
    lst.push_back(10);
    lst.push_back(30);
    lst.push_back(50);
    lst.push_back(70);
    lst.push_back(90);
    lst.push_back(110);
    lst.push_back(110);
    lst.push_back(110);
    list<int>::iterator it;
    lst.clear();
    cout<<"empty?="<<lst.empty() <<endl;
     
    return 0;
}

2.list.erase(beg,end);//删除[beg,end)区间的数据,返回下一个数据的位置,list.erase(pos);//删除pos位置的数据,返回下一个数据的位置

 #include <iostream>
#include <list>
using namespace std;

int main()
{
    list<int> lst, lst1;
    lst.push_back(10);
    lst.push_back(30);
    lst.push_back(50);
    list<int>::iterator it;
    it=lst.begin() ;
    it++;
    it++; 
    lst.erase(it);
    for(it = lst.begin(); it != lst.end(); ++it)
    {
        cout << *it << " ";
    }
    cout << endl;
    return 0;
}

3.Ist.remove(elem)://删除容器中所有与elem值匹配的元素

#include <iostream>
#include <list>
using namespace std;

int main()
{
    list<int> lst, lst1;
    lst.push_back(10);
    lst.push_back(30);
    lst.push_back(50);
    lst.push_back(70);
    lst.push_back(90);
    lst.push_back(110);
    lst.push_back(110);
    lst.push_back(110);
    list<int>::iterator it;
    lst.remove(110);
    for(it = lst.begin(); it != lst.end(); ++it)
    {
        cout << *it << " ";
    }
    cout << endl;
    return 0;
}


(三)list的反转

#include <iostream>
#include <list>
using namespace std;

int main()
{
    list<int> lst, lst1;
    lst.push_back(10);
    lst.push_back(30);
    lst.push_back(50);
    lst.push_back(70);
    lst.push_back(90);
    lst.push_back(110);
    list<int>::iterator it;
    lst.reverse() ;
    for(it=lst.begin() ;it!=lst.end() ;it++)
    {
        cout<<*it<<" ";
    }
    cout<<endl;
    return 0;
}

相关文章:

14-6-3C++STL的list

&#xff08;一&#xff09;list的插入 1.list.insert(pos,elem);//在pos位置插入一个elem元素的拷贝&#xff0c;返回新数据的位置 #include <iostream> #include <list> using namespace std; int main() { list<int> lst; lst.push_back(10); l…...

AAAI2024论文解读|HGPROMPT Bridging Homogeneous and Heterogeneous Graphs

论文标题 HGPROMPT: Bridging Homogeneous and Heterogeneous Graphs for Few-shot Prompt Learning 跨同构异构图的小样本提示学习 论文链接 HGPROMPT: Bridging Homogeneous and Heterogeneous Graphs for Few-shot Prompt Learning论文下载 论文作者 Xingtong Yu, Yuan…...

WPA_cli P2P命令详解及使用

目录 通用命令 status scan scan_results add_network set_network enable_network reconfigure save_config quit P2P 相关命令 p2p_find p2p_peers p2p_connect [method] p2p_group_add [ssid=] [freq=] [ht40] [persistent] p2p_remove_client p2p_di…...

【竞技宝】LPL:IG3-1击败RNG

北京时间1月26日&#xff0c;英雄联盟LPL2025正在如火如荼的进行之中&#xff0c;昨日共进行两场比赛。第二场比赛由RNG对阵IG。本场比赛&#xff0c;RNG在首局前期打出完美节奏后一直压制着IG拿下比赛&#xff0c;但此后的三局&#xff0c;IG发挥出自己擅长大乱斗的能力在团战…...

sqlite3 学习笔记

文章目录 前言SQL的概念与表格相关的操作i.创建表格&#xff08;增&#xff09;ii 删除表格&#xff08;删&#xff09;iii 更改表格&#xff08;改&#xff09;iv 查询表格&#xff08;查&#xff09; 与记录相关的操作i 插入记录ii 删除记录iii 查询记录iv 修改记录 Linux中使…...

Visual Studio Community 2022(VS2022)安装方法

废话不多说直接上图&#xff1a; 直接上步骤&#xff1a; 1&#xff0c;首先可以下载安装一个Visual Studio安装器&#xff0c;叫做Visual Studio installer。这个安装文件很小&#xff0c;很快就安装完成了。 2&#xff0c;打开Visual Studio installer 小软件 3&#xff0c…...

项目集成RabbitMQ

文章目录 1.common-rabbitmq-starter1.创建common-rabbitmq-starter2.pom.xml3.自动配置1.RabbitMQAutoConfiguration.java2.spring.factories 2.测试使用1.创建common-rabbitmq-starter-demo2.目录结构3.pom.xml4.application.yml5.TestConfig.java 配置交换机和队列6.TestCon…...

3097. 或值至少为 K 的最短子数组 II

3097. 或值至少为 K 的最短子数组 II 题目链接&#xff1a;3097. 或值至少为 K 的最短子数组 II 代码如下&#xff1a; class Solution { public:int minimumSubarrayLength(vector<int>& nums, int k) {int res INT_MAX;for (int i 0;i < nums.size();i) {in…...

Linux 35.6 + JetPack v5.1.4之编译器升级

Linux 35.6 JetPack v5.1.4之编译器升级 1. 源由2. 步骤步骤一&#xff1a;添加编译器源步骤二&#xff1a;安装gcc/g 11/13步骤三&#xff1a;确认安装版本步骤四&#xff1a;配置gcc/g版本步骤五&#xff1a;使能gcc/g版本步骤六&#xff1a;查看使能链接关系步骤七&#xf…...

[MoeCTF 2022]ezhtml

题目 查看页面源代码 有个/evil.js文件打开查看 看到了flag NSSCTF{e15f7f51-d1a0-4d1b-a96d-c987a4fe69a0} 到这里也就可以直接结束了 // 获取元素节点 var sx document.querySelector(#sx); // 获取 id 为 sx 的元素节点 var yw document.querySelector(#yw); // 获取…...

活动回顾和预告|微软开发者社区 Code Without Barriers 上海站首场活动成功举办!

Code Without Barriers 上海活动回顾 Code Without Barriers&#xff1a;AI & DATA 深入探索人工智能与数据如何变革行业 2025年1月16日&#xff0c;微软开发者社区 Code Without Barriers &#xff08;CWB&#xff09;携手 She Rewires 她原力在大中华区的首场活动“AI &…...

使用 Redis List 和 Pub/Sub 实现简单的消息队列

使用 Redis List 和 Pub/Sub 实现简单的消息队列 Redis 本身不是专门的消息队列系统&#xff0c;但它提供了多种数据结构&#xff08;如 List、Pub/Sub、Stream&#xff09;来实现消息队列功能。根据不同的业务需求&#xff0c;可以选择不同的方式&#xff1a; 在 Redis 中&a…...

本地项目上传到码云

本地项目上传到码云 写在前面1. 系统安装git环境2. 创建仓库3. 开始上传3.1 创建新的远程仓库3.2 在项目的文件夹用git打开3.3 删除本地的 .git 目录3.4 初始化新的 Git 仓库3.5 添加远程仓库3.6 添加项目文件3.7 提交更改3.8 推送到远程仓库3.9 验证 4. 完整的步骤总结写在最后…...

Ansible入门学习之基础元素介绍

一、Ansible目录结构介绍 1.通过rpm -ql ansible获取ansible所有文件存放的目录 有配置文件目录 /etc/ansible/ 执行文件目录 /usr/bin/ 其中 /etc/ansible/ 该文件目录的主要功能是 inventory主机信息配置&#xff0c;ansible工具功能配置。 ansible自身的配置文件…...

大数据治理实战指南:数据质量、合规与治理架构

&#x1f4dd;个人主页&#x1f339;&#xff1a;一ge科研小菜鸡-CSDN博客 &#x1f339;&#x1f339;期待您的关注 &#x1f339;&#x1f339; 引言 随着企业数字化转型的加速&#xff0c;大数据已成为驱动业务决策的核心资产。然而&#xff0c;数据治理的缺失或不完善&…...

leetcode_链表 234.回文链表

234.回文链表 给你一个单链表的头节点head&#xff0c;请你判断该链表是否为回文链表。如果是, 返回 true ; 否则, 返回false。思路&#xff1a; 找到中间节点(快慢指针法)反转后半部分的链表比较前半部分和后半部分链表 # Definition for singly-linked list. # class List…...

[Dialog屏幕开发] 屏幕绘制(下拉菜单)

阅读该篇文章之前&#xff0c;可先阅读下述资料 [Dialog屏幕开发] Table Control 列数据操作https://blog.csdn.net/Hudas/article/details/145343731?spm1001.2014.3001.5501https://blog.csdn.net/Hudas/article/details/145343731?spm1001.2014.3001.5501https://blog.cs…...

deepseek v1手机端部署

在iPhone上部署DeepSeekR1 1. 安装快捷指令&#xff1a; 打开iPhone上的Safari浏览器&#xff0c;访问[这个链接](https://www.icloud.com/shortcuts/e0bc5445c39d45a78b90e1dc896cd010)下载快捷指令。 下载后&#xff0c;按照提示完成安装。 2. 获取并配置API Key&a…...

CVPR 2024 无人机/遥感/卫星图像方向总汇(航空图像和交叉视角定位)

1、UAV、Remote Sensing、Satellite Image(无人机/遥感/卫星图像) Unleashing Unlabeled Data: A Paradigm for Cross-View Geo-Localization ⭐codeRethinking Transformers Pre-training for Multi-Spectral Satellite Imagery ⭐codeAerial Lifting: Neural Urban Semantic …...

【信息系统项目管理师-选择真题】2015下半年综合知识答案和详解

更多内容请见: 备考信息系统项目管理师-专栏介绍和目录 文章目录 【第1题】【第2题】【第3题】【第4题】【第5题】【第6题】【第7题】【第8题】【第9题】【第10题】【第11题】【第12题】【第13题】【第14题】【第15题】【第16题】【第17题】【第18题】【第19题】【第20题】【第…...

脑机新手指南(八):OpenBCI_GUI:从环境搭建到数据可视化(下)

一、数据处理与分析实战 &#xff08;一&#xff09;实时滤波与参数调整 基础滤波操作 60Hz 工频滤波&#xff1a;勾选界面右侧 “60Hz” 复选框&#xff0c;可有效抑制电网干扰&#xff08;适用于北美地区&#xff0c;欧洲用户可调整为 50Hz&#xff09;。 平滑处理&…...

CMake基础:构建流程详解

目录 1.CMake构建过程的基本流程 2.CMake构建的具体步骤 2.1.创建构建目录 2.2.使用 CMake 生成构建文件 2.3.编译和构建 2.4.清理构建文件 2.5.重新配置和构建 3.跨平台构建示例 4.工具链与交叉编译 5.CMake构建后的项目结构解析 5.1.CMake构建后的目录结构 5.2.构…...

Nginx server_name 配置说明

Nginx 是一个高性能的反向代理和负载均衡服务器&#xff0c;其核心配置之一是 server 块中的 server_name 指令。server_name 决定了 Nginx 如何根据客户端请求的 Host 头匹配对应的虚拟主机&#xff08;Virtual Host&#xff09;。 1. 简介 Nginx 使用 server_name 指令来确定…...

Module Federation 和 Native Federation 的比较

前言 Module Federation 是 Webpack 5 引入的微前端架构方案&#xff0c;允许不同独立构建的应用在运行时动态共享模块。 Native Federation 是 Angular 官方基于 Module Federation 理念实现的专为 Angular 优化的微前端方案。 概念解析 Module Federation (模块联邦) Modul…...

leetcodeSQL解题:3564. 季节性销售分析

leetcodeSQL解题&#xff1a;3564. 季节性销售分析 题目&#xff1a; 表&#xff1a;sales ---------------------- | Column Name | Type | ---------------------- | sale_id | int | | product_id | int | | sale_date | date | | quantity | int | | price | decimal | -…...

全志A40i android7.1 调试信息打印串口由uart0改为uart3

一&#xff0c;概述 1. 目的 将调试信息打印串口由uart0改为uart3。 2. 版本信息 Uboot版本&#xff1a;2014.07&#xff1b; Kernel版本&#xff1a;Linux-3.10&#xff1b; 二&#xff0c;Uboot 1. sys_config.fex改动 使能uart3(TX:PH00 RX:PH01)&#xff0c;并让boo…...

图表类系列各种样式PPT模版分享

图标图表系列PPT模版&#xff0c;柱状图PPT模版&#xff0c;线状图PPT模版&#xff0c;折线图PPT模版&#xff0c;饼状图PPT模版&#xff0c;雷达图PPT模版&#xff0c;树状图PPT模版 图表类系列各种样式PPT模版分享&#xff1a;图表系列PPT模板https://pan.quark.cn/s/20d40aa…...

tree 树组件大数据卡顿问题优化

问题背景 项目中有用到树组件用来做文件目录&#xff0c;但是由于这个树组件的节点越来越多&#xff0c;导致页面在滚动这个树组件的时候浏览器就很容易卡死。这种问题基本上都是因为dom节点太多&#xff0c;导致的浏览器卡顿&#xff0c;这里很明显就需要用到虚拟列表的技术&…...

【开发技术】.Net使用FFmpeg视频特定帧上绘制内容

目录 一、目的 二、解决方案 2.1 什么是FFmpeg 2.2 FFmpeg主要功能 2.3 使用Xabe.FFmpeg调用FFmpeg功能 2.4 使用 FFmpeg 的 drawbox 滤镜来绘制 ROI 三、总结 一、目的 当前市场上有很多目标检测智能识别的相关算法&#xff0c;当前调用一个医疗行业的AI识别算法后返回…...

优选算法第十二讲:队列 + 宽搜 优先级队列

优选算法第十二讲&#xff1a;队列 宽搜 && 优先级队列 1.N叉树的层序遍历2.二叉树的锯齿型层序遍历3.二叉树最大宽度4.在每个树行中找最大值5.优先级队列 -- 最后一块石头的重量6.数据流中的第K大元素7.前K个高频单词8.数据流的中位数 1.N叉树的层序遍历 2.二叉树的锯…...