首页 > 其他分享 >2022.02.12.list-map

2022.02.12.list-map

时间:2023-01-06 11:45:34浏览次数:43  
标签:map 12 iterator 迭代 ite list lst push 节点

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

//iterator  迭代器:遍历容器(list)

void show(int v){
    cout<<v<<" ";
}

int main(){

    list<int> lst;   //定义链表

    lst.push_back(1);//尾添加
    lst.push_back(2);
    lst.push_back(3);
    lst.push_back(4);
    lst.push_front(6);// 头添加

    list<int>::iterator ite;//定义迭代器
    ite = lst.begin();      //返回头节点迭代器
    while(ite!=lst.end()){  //end为尾结点迭代器
        cout<<*ite<<" ";
        ite++;
    }
    cout<<endl;

    lst.pop_back();//头删除
    lst.pop_front();//尾删除

    //增强for循环输出删除后的
    for(int val:lst){
        cout<<val<<" ";
    }
    cout<<endl;

    cout<<lst.front()<<" "<<lst.back()<<endl;

    cout<<"链表的长度"<<lst.size()<<endl;

    //lst.clear();//链表清空

    if(lst.empty()){
        cout<<"链表为空"<<endl;
    }else{
        cout<<"链表bu为空"<<endl;
    }

    ite=++lst.begin();
    list<int>::iterator ite2=lst.insert(ite,10);//在指向的节点之前插入,返回插入的节点
    
    cout<<*ite2<<endl;
    for(int val:lst){
        cout<<val<<" ";
    }
    cout<<endl;

    ite = ++lst.begin();
    /*list<int>::iterator ite3=lst.erase(ite);*///删除迭代器指向的节点,该迭代器将失效,返回的删除节点的下一个节点的迭代器
    ite=lst.erase(ite);
    cout<<*ite<<endl;

    /*cout<<*ite3<<endl;*/
    for(int val:lst){
        cout<<val<<" ";
    }
    cout<<endl;


        cout<<"_______________"<<endl;


        ::for_each(lst.begin(),lst.end(),&show);
        cout<<endl;

        cout<<*lst.begin()<<endl;
        cout<<*(--lst.end())<<endl;

    system("pause");
        return 0;
}

 

标签:map,12,iterator,迭代,ite,list,lst,push,节点
From: https://www.cnblogs.com/hualuoyumufeng/p/15949611.html

相关文章

  • 2022.02.12.operator
    重载操作符operator:在程序中与到这个符号,通过调用当前重载操作符函数来行使操作符的功能,一般是有返回值,为了和后续的操作符继续操作,匹配操作符根据重载操作符函数的参数......
  • 『中级篇』docker架构和底层技术(12)
    ​前11节主要是介绍docker的安装,如果跟这我来学我相信大家已经有了一个docker的安装环境,本次是看下docker的架构和底层的技术,其实随着各位老铁的学习我相信对于docker架......
  • replit搭建的alist如何进行升级
    replit搭建的alist如何进行升级本文章同样发布于我的个人博客:Aprdec'sskyalist可以用replit白嫖应该很多人都知道了,而且点进来的估计99%都是用replit搭建的,不得不说,......
  • 【集合】LeetCode 128. 最长连续序列
    题目链接128.最长连续序列思路题目要求找连续序列,且时间复杂度读要求O(n),可以使用集合进行实现。代码classSolution{publicintlongestConsecutive(int[]nu......
  • Drawable与Bitmap详解
    Drawable与Bitmap对比定义对比:Bitmap:称作位图,一般的位图的文件格式扩展名为.bmp,当然编码器也有很多,RGB565,RGB8888,作为一种追个像素的显示对象,执行效率高,但是存储效率低,可以......
  • BitmapFactory.Options参数作用
    参数作用BitmapFactory.Options这个参数可以设置Bitmap的采样率,通过该比那图片的宽度、高度、缩放比例等,以达到减少图片的像素的目的,设置这个值可以更好的控制、显示和使用B......
  • 高阶函数map和filter
    1.高阶函数内建高阶函数:map()、filter()高阶函数至少满足两个任意的一个条件能接收一个或多个函数作为输入输出一个函数2.高阶函数map的使用map()函数:根据......
  • 解决Consider defining a bean of type ‘*Mapper‘ in your configuration.
    pom.xml<dependency><groupId>org.mybatis.spring.boot</groupId><artifactId>mybatis-spring-boot-starter</artifactId><version>2.0.1</version></depen......
  • list双链表
    structlistnode{structlistnode*next;structlistnode*prev;void*data;};structlist_head{ structlist_head*next,*prev;};/*Linkedlistof......
  • C#(Java)将List集合构建成Tree树
    C#(Java)将List集合构建成Tree树子安树构建算法,可以通过空间换时间进一步优化速度树结构的类publicclassMyTreeNode{publicMyTreeNode(long?iD,long?pare......