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

//底层结构是双向链表

struct Node{
int a;
char c;

};

struct Node1{ //重点中的重点
int a;
char c;
Node1(int d,char e)
{
a=d;
c=e;
}
bool operator==(const Node1& i)
{
if(i.a==this->a&&i.c==this->c)
{
return true;
}
return false;
}

bool operator<(const Node1& f)
{
if(this->a<f.a) //if(this->a>f.a) //可以改变> , <
return true;
return false;
}
};

void fun(Node d)
{
cout << d.a << " " << d.c << "\n";
}

void fun1(Node1 d)
{
cout << d.a << " " << d.c << "\n";
}

void listdefine()
{
list<Node> ls;
list<Node> l(5);
Node no={12,'a'};
list<Node> l1(5,no);
list<Node> l2(l1);
list<Node> l3(l2.begin(),l2.end());

list<Node>::iterator ite=l3.begin(); //不可以加数,只可以自加,
ite++; //ite+4; 错误
list<Node>l4(ite,l3.end());

//for_each(l3.begin(),l3.end(),fun);
for_each(l4.begin(),l4.end(),fun);
}

void listsize()
{
Node no={12,'a'};
list<Node> ls(6,no);

cout << ls.size() << endl;

//for_each(ls.begin(),ls.end(),fun);

ls.resize(18); //新扩空间全为0

cout << ls.size() << endl;

for_each(ls.begin(),ls.end(),fun);

ls.resize(3);

cout << ls.size() << endl;

//cout << ls.empty() << endl;

ls.resize(0);

//cout << ls.empty() << endl;
}

void list_put_increase()
{
//Node no={12,'a'};
//list<Node> ls(5,no);

//输出:循环,迭代器,for_each(不支持下标运算
/*
for(list<Node>::iterator ite=ls.begin();ite!=ls.end();ite++)
{
cout << ite->a << " " << ite->c << endl;
}
*/
//cout << ls.back().a << " " << ls.back().c << endl;
//cout << ls.front().a << " " << ls.front().c << endl;
//list<Node> l1;
//ls.push_front(no);
//for_each(ls.begin(),ls.end(),fun);
list<Node1> li;
li.push_front(Node1(12,'a')); //头添加
li.push_back(Node1(13,'b')); //尾添加
list<Node1>::iterator ite=li.begin();
ite++;
li.insert(ite,Node1(15,'c'));
ite--;
li.insert(ite,3,Node1(16,'d'));
cout << ite->a << endl;

for_each(li.begin(),li.end(),fun1);
}

void list_delete_modification()//
{
list<Node1> ls;
ls.push_front(Node1(12,'a'));
ls.push_back(Node1(13,'b'));
list<Node1>::iterator ite=ls.begin();
ls.insert(++ite,3,Node1(14,'c'));

for_each(ls.begin(),ls.end(),fun1);

//ls.pop_back(); //尾删除
//ls.pop_front(); //头删除
//ls.erase(ls.begin(),--ls.end()); //选位删除
//ls.clear(); //清空
//ls.unique(); //去重

//ls.assign(3,Node1(11,'x')); //重新赋值
ls.begin()->a=(--ls.end())->a; //改
//还可以用迭代器

for_each(ls.begin(),ls.end(),fun1);
}

void list_merge()
{
list<Node1> ls;
ls.push_front(Node1(12,'a'));
ls.push_back(Node1(13,'b'));
ls.insert(++ls.begin(),3,Node1(14,'c'));

list<Node1> ls1;
ls1.push_front(Node1(1,'x'));
ls1.push_front(Node1(25,'y'));
ls1.push_back(Node1(3,'z'));
ls.merge(ls1); //合并

//ls1.swap(ls); //交换

//ls.reverse(); //倒序 //reserve

//ls.sort(); //从小到大

//ls.splice(); //拼接

list<Node1>::iterator ite=find(ls.begin(),ls.end(),Node1(12,'a')); //find需要重载==号 Node1(12,'f')也不影响
cout << ite->a << " " << ite->c << endl;

for_each(ls.begin(),ls.end(),fun1);
}

int main()
{
//listdefine();
//listsize();
//list_put_increase();
//list_delete_modification();
//list_merge();
return 0;
}

/*
与vector的区别:
随机访问慢,也支持下标,快速插入删除

forward_list容器,2011年以后的编译器可用,更快,无size函数

*/

stl_list复习的更多相关文章

  1. iOS总结_UI层自我复习总结

    UI层复习笔记 在main文件中,UIApplicationMain函数一共做了三件事 根据第三个参数创建了一个应用程序对象 默认写nil,即创建的是UIApplication类型的对象,此对象看成是 ...

  2. vuex复习方案

    这次复习vuex,发现官方vuex2.0的文档写得太简略了,有些看不懂了.然后看了看1.0的文档,感觉很不错.那以后需要复习的话,还是先看1.0的文档吧.

  3. 我的操作系统复习——I/O控制和系统调用

    上篇博客介绍了存储器管理的相关知识——我的操作系统复习——存储器管理,本篇讲设备管理中的I/O控制方式和操作系统中的系统调用. 一.I/O控制方式 I/O就是输入输出,I/O设备指的是输入输出设备和存 ...

  4. 复习(1)【Maven】

    终于开始复习旧知识了,有输入必然要有输出.输入和输出之间的内化过程尤为重要,在复习的同时,真正把学到的东西积淀下来,加深理解. Maven项目概念与配置 Maven是一个项目管理和综合工具.Maven ...

  5. 《CSS权威指南》基础复习+查漏补缺

    前几天被朋友问到几个CSS问题,讲道理么,接触CSS是从大一开始的,也算有3年半了,总是觉得自己对css算是熟悉的了.然而还是被几个问题弄的"一脸懵逼"... 然后又是刚入职新公司 ...

  6. JS复习--更新结束

    js复习-01---03 一 JS简介 1,文档对象模型 2,浏览器对象模型 二 在HTML中使用JS 1,在html中使用<script></script>标签 2,引入外部 ...

  7. jQuery 复习

    jQuery 复习 基础知识 1, window.onload $(function(){});   $(document).ready(function(){}); 只执行函数体重的最后一个方法,事 ...

  8. jQuery5~7章笔记 和 1~3章的复习笔记

    JQery-05 对表单和表格的操作及其的应用 JQery-06 jQuery和ajax的应用 JQery-07 jQuery插件的使用和写法 JQery-01-03 复习 之前手写的笔记.实在懒得再 ...

  9. HTML和CSS的复习总结

    HTML(Hypertext Markup Language)超文本标记语言:其核心就是各种标记!<html> HTML页面中的所有内容,都在该标签之内:它主要含<head>和 ...

随机推荐

  1. eclipse运用经验

    1.eclipse粘贴字符串添加转义符 2.eclipse的jdk版本切换 1.Window—Preferences—Java—Compiler—右侧面板设置为1.6 2.Window—Prefere ...

  2. hadoop中遇到的各种错误记录

    hadoop中namenode无法启动          转载链接:https://blog.csdn.net/love666666shen/article/details/74350358 使用pi ...

  3. ieee-explore文献免费下载办法

    假设文献网址为:http://ieeexplore.ieee.org/document/xxxxxxx/ 下载保存的话,改为http://ieeexplore.ieee.org.sci-hub.tw/ ...

  4. Go_json

    package main import ( "encoding/json" "fmt" ) // 结构体与json // 1.序列化: 把Go语言中的结构体变量 ...

  5. unittest的discover方法

    转载:https://www.cnblogs.com/imyalost/p/9048386.html discover()方法 discover(start_dir, pattern ='test * ...

  6. 19年SD夏令营游记

    首先,因为自己的刻苦学习(tui),所以游记很短,勿喷... 7.22.2019——报到 话说昨晚热到12点才睡着,在路上大家一直都在玩游戏,没有游戏可玩的我听着歌发呆... 到了山东省外国语职业技术 ...

  7. codeforces E. The Contest(最长上升子序列)

    题目链接:https://codeforces.com/contest/1257/problem/E 题意:给三个序列k1,k2,k3,每个序列有一堆数,k1是前缀,k3是后缀,k2是中间,现可以从任 ...

  8. docker互联机制实现便捷互访

    何为容器互联 & 为何需要容器互联 容器的互联是一种让多个容器中应用进行快速交互的方式,它会在源和接收容器之间创建连接关系,接收容器可以通过容器名快速访问到源容器,而不用指定具体的 ip 地址 ...

  9. 线性递推BM模板

    #include <cstdio> #include<iostream> #include <cstring> #include <cmath> #in ...

  10. Java中查询某个日期下所有时间段的数据

    除了利用时间段进行查询外,还有一个方法: 利用mybatis中的函数,将datetime转为date <if test="purch_date!= null and purch_dat ...