#include <iostream>
#include <list> using namespace std; int main()
{
// list可以在头部和尾部插入和删除元素
// 不能随机访问元素,迭代器只能++,不能一次性跳转
list<int> L;
//L.push(1);
L.push_back();
L.push_front();
L.push_back(); for(list<int>::iterator it=L.begin();it!=L.end();++it)
{
// it=L.begin()+1也不行
cout<<*it<<' ';
//it+=1;
//it=it+1;
}
cout<<endl; //删除
//erase
list<int>::iterator it=L.begin();
++it;
L.erase(it); for(list<int>::iterator it=L.begin();it!=L.end();++it)
{
cout<<*it<<' ';
}
cout<<endl; // remove ->值删除
L.remove();
for(list<int>::iterator it=L.begin();it!=L.end();++it)
{
cout<<*it<<' ';
}
cout<<endl;
L.remove();
for(list<int>::iterator it=L.begin();it!=L.end();++it)
{
cout<<*it<<' ';
}
cout<<endl; return ;
}

STL-list 链表的更多相关文章

  1. STL list链表的用法详解

    本文以List容器为例子,介绍了STL的基本内容,从容器到迭代器,再到普通函数,而且例子丰富,通俗易懂.不失为STL的入门文章,新手不容错过! 0 前言 1 定义一个list 2 使用list的成员函 ...

  2. 02-线性结构3 Reversing Linked List(25 point(s)) 【链表】

    02-线性结构3 Reversing Linked List(25 point(s)) Given a constant K and a singly linked list L, you are s ...

  3. bullet HashMap 内存紧密的哈希表

    last modified time:2014-11-9 14:07:00 bullet 是一款开源物理引擎,它提供了碰撞检測.重力模拟等功能,非常多3D游戏.3D设计软件(如3D Mark)使用它作 ...

  4. clientdataset 做为 单机数据库的 使用 学习

    http://blog.csdn.net/waveyang/article/details/34146737 unit Unit3; interface uses Winapi.Windows, Wi ...

  5. 2021.8.11考试总结[NOIP模拟36]

    T1 Dove玩扑克 考场并查集加树状数组加桶期望$65pts$实际$80pts$,考后多开个数组记哪些数出现过,只扫出现过的数就切了.用$set$维护可以把被删没的数去掉,更快. $code:$ 1 ...

  6. Uva 11988 Broken Keyboard STL+链表

    两种方法,直接上代码 STL标准模板库 #include <iostream> #include <list> #include <algorithm> #incl ...

  7. 使用STL中的list容器实现单链表的操作

    #include<iostream> #include<list> #include<algorithm> using namespace std; void Pr ...

  8. C语言实现简单的单向链表(创建、插入、删除)及等效STL实现代码

    实现个算法,懒得手写链表,于是用C++的forward_list,没有next()方法感觉很不好使,比如一个对单向链表的最简单功能要求: input: 1 2 5 3 4 output: 1-> ...

  9. Codeforces 1131 F. Asya And Kittens-双向链表(模拟或者STL list)+并查集(或者STL list的splice()函数)-对不起,我太菜了。。。 (Codeforces Round #541 (Div. 2))

    F. Asya And Kittens time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  10. STL 中的链表排序

    一直以来学习排序算法, 都没有在链表排序上下太多功夫,因为用得不多.最近看STL源码,才发现,原来即使是链表,也能有时间复杂度为O(nlogn)的算法, 大大出乎我的意料之外,一般就能想到个插入排序. ...

随机推荐

  1. WeChall_Training: Encodings I (Training, Encoding)

    We intercepted this message from one challenger to another, maybe you can find out what they were ta ...

  2. sqlserver install on linux chapter one

    Hello The MS open the source to let people download source. You may ask where to download ? Ask goog ...

  3. angularJS 传参的四种方法

    AngularJS - Passing data between pages 著作权归作者所有.商业转载请联系作者获得授权,非商业转载请注明出处.作者:Ye Huang链接:https://www.z ...

  4. vs 搭配 Linux 开发

    这是一篇翻译,为什么突然想翻译文章了呢,因为很多大佬们都说英语对程序员还是挺重要的,毕竟互联网的最新技术基本都在歪果仁那边,如果英语不好,不会看国外的文档的话,将会错失接触第一手资料的机会,失去很多先 ...

  5. LNK2019

    原因:inline函数被外部文件的函数调用时,必须将inline函数定义在头文件中,不能定义在cpp文件中.

  6. golang搭建一个简单的web服务器

    package main import ( "io/ioutil" "log" "net/http" ) func main() { htt ...

  7. php面试笔记(4)-php基础知识-流程控制

    本文是根据慕课网Jason老师的课程进行的PHP面试知识点总结和升华,如有侵权请联系我进行删除,email:guoyugygy@163.com 在面试中,考官往往喜欢基础扎实的面试者,而流程控制相关的 ...

  8. display:table的用法

    目前,在大多数开发环境中,已经基本不用table元素来做网页布局了,取而代之的是div+css,那么为什么不用table系表格元素呢? 1.用DIV+CSS编写出来的文件k数比用table写出来的要小 ...

  9. File类和枚举

    java.io.File类:文件和目录路径名的抽象表示形式 File类常见构造方法: File(String pathname):通过将给定路径名字符串转换为抽象路径名来创建一个新 File 实例. ...

  10. GNU make doc - 3.8

    Note that the directory prefix (D), as described in Implicit Rule Search Algorithm, is appended (aft ...