当前位置: 首页 > 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题】【第…...

conda相比python好处

Conda 作为 Python 的环境和包管理工具&#xff0c;相比原生 Python 生态&#xff08;如 pip 虚拟环境&#xff09;有许多独特优势&#xff0c;尤其在多项目管理、依赖处理和跨平台兼容性等方面表现更优。以下是 Conda 的核心好处&#xff1a; 一、一站式环境管理&#xff1a…...

【Python】 -- 趣味代码 - 小恐龙游戏

文章目录 文章目录 00 小恐龙游戏程序设计框架代码结构和功能游戏流程总结01 小恐龙游戏程序设计02 百度网盘地址00 小恐龙游戏程序设计框架 这段代码是一个基于 Pygame 的简易跑酷游戏的完整实现,玩家控制一个角色(龙)躲避障碍物(仙人掌和乌鸦)。以下是代码的详细介绍:…...

【kafka】Golang实现分布式Masscan任务调度系统

要求&#xff1a; 输出两个程序&#xff0c;一个命令行程序&#xff08;命令行参数用flag&#xff09;和一个服务端程序。 命令行程序支持通过命令行参数配置下发IP或IP段、端口、扫描带宽&#xff0c;然后将消息推送到kafka里面。 服务端程序&#xff1a; 从kafka消费者接收…...

模型参数、模型存储精度、参数与显存

模型参数量衡量单位 M&#xff1a;百万&#xff08;Million&#xff09; B&#xff1a;十亿&#xff08;Billion&#xff09; 1 B 1000 M 1B 1000M 1B1000M 参数存储精度 模型参数是固定的&#xff0c;但是一个参数所表示多少字节不一定&#xff0c;需要看这个参数以什么…...

Cesium1.95中高性能加载1500个点

一、基本方式&#xff1a; 图标使用.png比.svg性能要好 <template><div id"cesiumContainer"></div><div class"toolbar"><button id"resetButton">重新生成点</button><span id"countDisplay&qu…...

ArcGIS Pro制作水平横向图例+多级标注

今天介绍下载ArcGIS Pro中如何设置水平横向图例。 之前我们介绍了ArcGIS的横向图例制作&#xff1a;ArcGIS横向、多列图例、顺序重排、符号居中、批量更改图例符号等等&#xff08;ArcGIS出图图例8大技巧&#xff09;&#xff0c;那这次我们看看ArcGIS Pro如何更加快捷的操作。…...

算法岗面试经验分享-大模型篇

文章目录 A 基础语言模型A.1 TransformerA.2 Bert B 大语言模型结构B.1 GPTB.2 LLamaB.3 ChatGLMB.4 Qwen C 大语言模型微调C.1 Fine-tuningC.2 Adapter-tuningC.3 Prefix-tuningC.4 P-tuningC.5 LoRA A 基础语言模型 A.1 Transformer &#xff08;1&#xff09;资源 论文&a…...

MySQL 索引底层结构揭秘:B-Tree 与 B+Tree 的区别与应用

文章目录 一、背景知识&#xff1a;什么是 B-Tree 和 BTree&#xff1f; B-Tree&#xff08;平衡多路查找树&#xff09; BTree&#xff08;B-Tree 的变种&#xff09; 二、结构对比&#xff1a;一张图看懂 三、为什么 MySQL InnoDB 选择 BTree&#xff1f; 1. 范围查询更快 2…...

android RelativeLayout布局

<?xml version"1.0" encoding"utf-8"?> <RelativeLayout xmlns:android"http://schemas.android.com/apk/res/android"android:layout_width"match_parent"android:layout_height"match_parent"android:gravity&…...

深入浅出Diffusion模型:从原理到实践的全方位教程

I. 引言&#xff1a;生成式AI的黎明 – Diffusion模型是什么&#xff1f; 近年来&#xff0c;生成式人工智能&#xff08;Generative AI&#xff09;领域取得了爆炸性的进展&#xff0c;模型能够根据简单的文本提示创作出逼真的图像、连贯的文本&#xff0c;乃至更多令人惊叹的…...