STL 小白学习(7) list
#include <iostream>
using namespace std;
#include <list> void printList(list<int>& mlist) { for (list<int>::iterator it = mlist.begin(); it != mlist.end(); it++) {
cout << *it << " ";
}
cout << endl; }
//初始化
void test01() {
list<int> myList;
list<int> myList2(, );//有参构造
list<int> list3(myList2);
//有参构造
list<int>mlist4(myList2.begin(), myList2.end()); //打印
for (list<int>::iterator it = list3.begin(); it != list3.end(); it++) {
cout << *it << " ";
}
cout << endl;
} //list 插入删除
void test02() {
list<int> mlist;
mlist.push_back();
mlist.push_front();
//插入
mlist.insert(mlist.begin(), );
//在指定位置插入
list<int>::iterator it = mlist.begin();
it++;
mlist.insert(it, );
//在尾部插入
mlist.insert(mlist.end(), );
//删除
mlist.pop_back();
mlist.pop_front();
//删除区间
mlist.erase(mlist.begin(), mlist.end());
mlist.clear(); //.remove 删除
mlist.push_front();
mlist.push_back();
mlist.push_front();
mlist.remove();//删掉所有匹配的元素
printList(mlist); } // size empty略 //赋值操作
void test03() {
list<int> mlist;
mlist.assign(, ); list<int> mlist2;
mlist2 = mlist; mlist2.swap(mlist);
} //排序反转
void test04() {
list<int> mlist = { ,,,,,,, };
mlist.reverse();
printList(mlist);
} bool myCompare(int a, int b) {
return a > b;
}
//排序
void test05() {
list<int> mlist = { ,,,,,,, };
mlist.sort();//基础数据类型 默认排序 从小到大
printList(mlist);
mlist.sort(myCompare);//自己写回调函数 从大到小排序
printList(mlist); //算法 sort 支持可随机访问容量 } int main() {
test05();
}
STL 小白学习(7) list的更多相关文章
- STL 小白学习(1) 初步认识
#include <iostream> using namespace std; #include <vector> //动态数组 #include <algorithm ...
- STL 小白学习(10) map
map的构造函数 map<int, string> mapS; 数据的插入:用insert函数插入pair数据,下面举例说明 mapStudent.insert(pair<, &qu ...
- STL 小白学习(9) 对组
void test01() { //构造方法 pair<, ); cout << p1.first << p1.second << endl; pair< ...
- STL 小白学习(8) set 二叉树
#include <iostream> using namespace std; #include <set> void printSet(set<int> s) ...
- STL 小白学习(5) stack栈
#include <iostream> #include <stack> //stack 不遍历 不支持随机访问 必须pop出去 才能进行访问 using namespace ...
- STL 小白学习(6) queue
//queue 一端插入 另一端删除 //不能遍历(不提供迭代器) 不支持随机访问 #include <queue> #include <iostream> using nam ...
- STL 小白学习(4) deque
#include <iostream> #include <deque> //deque容器 双口 using namespace std; void printDeque(d ...
- STL 小白学习(3) vector
#include <iostream> using namespace std; #include <vector> void printVector(vector<in ...
- STL 小白学习(2) string
#include <iostream> using namespace std; #include <string> //初始化操作 void test01() { //初始化 ...
随机推荐
- Pytrhon结束死循环的子线程
Python在子线程无线循环的过程中,如果直接ctrl+c结束程序的话,虽然程序可以结束,但是会导致子线程资源无法回收,一般情况不会有太大影响,但是使用TCP通信的时候,子线程是占用特定的端口的,在资 ...
- 996.icu,不加班的程序员有前途吗?
一.有没有不加班的程序员? 有,我就是. 我目前工作与一家500强外企(欧美),职称为高级软件开发专家. 我在这家公司(500强外企)已经服务了10年,所有加班次数合起来不超过10天,最近3年则一次都 ...
- hiho一下 第206周
题目1 : Guess Number with Lower or Higher Hints 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 There is a game ...
- MySQL文档翻译(八)附英文原文---性能优化概览
优化概述 数据库性能表现依赖于数据库级别的几个因素,比如表,查询和配置设置.这些软件在硬件级别通过CPU和IO操作构筑结果,你需要尽可能的使用最少的资源达到最大的效果.当你专注于数据库的性能表现时,你 ...
- 换个角度聊聊FaaS
Serverless/FaaS伴随着k8s的热度增加,也成为了热门话题.相关文章介绍了很多,这里笔者不一一赘述,而是从个人见解上聊聊关于FaaS的架构和意义. FaaS可能的架构优化 从AppEngi ...
- freeswitch替换默认保持音乐
1.编译vars.xml文件 上面为注释,下面为新增.指定系统音乐文件路径,reloadxml即可!
- JS(JavaScript)的初了解8(更新中···)
1.函数都有返回值…… 而方法的本质也是函数,所以也有返回值. Document.getElementById() 返回的是获取的标签 getElementsByClassName()和getElem ...
- 【POJ 1179】Polygon
[原题链接]传送门 [题解思路] 1.第一感觉没有其他做法,想到动态规划,去环,区间dp 2.f[l,r]表示[l,r]内的最大值,考虑转移 3.最大值分加法和乘法,其中乘法不一定由两个要求合并的区间 ...
- linux服务基础(三)之Httpd2.4配置
httpd-2.4 新特性: . MPM支持运行DSO机制,以模块形式按需加载 . 支持event MPM . 支持异步读写 . 支持每模块及每个目录分别使用各自的日志级别 . 每请求配置 <I ...
- Spring Boot 2 整合Swagger简单入门
Swagger是一款RESTFUL接口的文档在线自动生成+功能测试功能软件. 1.pom.xml添加配置 可以到http://mvnrepository.com上搜索springfox,便可以看到Sp ...