STL
STL
_Peko_
这个作者很懒,什么都没留下…
展开
-
vector 、list 、deque 容器的选择
vector 、list 、deque这三个容器的方法都差不多一样,那实际应用应该如何选择呢?1、如果你需要高效的随即存取,而不在乎插入和删除的效率,使用vector 2、如果你需要大量的插入和删除,而不关心随即存取,则应使用list 3、如果你需要随即存取,而且关心两端数据的插入和删除,则应使用deque。引用:https://www.cnblogs.com/...原创 2020-04-05 12:40:14 · 133 阅读 · 0 评论 -
【STL】 29 常用算术生成算法
转载 2020-03-16 18:35:55 · 115 阅读 · 0 评论 -
【STL】 27 常用排序算法
转载 2020-03-16 18:24:50 · 71 阅读 · 0 评论 -
【STL】 28 常用拷贝和替换算法
转载 2020-03-16 18:29:56 · 95 阅读 · 0 评论 -
【STL】 30 常用集合算法
#include<iostream>#include<vector>#include<algorithm>using namespace std;void MyPrint1(vector<int> & v){ for(vector<int>::iterator it = v.begin();it!=v...原创 2020-03-16 23:04:23 · 97 阅读 · 0 评论 -
【STL】01 基本概念
转载 2019-02-26 18:55:20 · 134 阅读 · 0 评论 -
【STL】02 容器算法迭代器分离
#include<iostream>using namespace std;//算法 统计某个元素的个数int MyCount(int* Begin,int* End,int val){ int num= 0; while(Begin!=End){ if(*Begin == val) num++; ...原创 2019-02-26 18:52:50 · 143 阅读 · 0 评论 -
【STL】03 Hello World
#include<iostream>#include<vector> //动态数组 可变数组#include<algorithm> //算法using namespace std;//STL基本语法void PrintVector(int v){ cout<<v<<" ";}void test...原创 2019-02-26 18:55:29 · 88 阅读 · 0 评论 -
【STL】04 string操作
#include<iostream>#include<string>using namespace std;void test01(){ string s1; //调用无参构造 string s2(10,'a'); string s3("Hello"); string s4(s3); //调用拷贝构造 c...原创 2019-02-26 18:55:34 · 142 阅读 · 0 评论 -
【STL】05 vector操作
#include<iostream>#include<vector> using namespace std;void Print_Vector(vector<int>& v){ for(vector<int>::iterator i=v.begin();i!=v.end();i++) cout<<...原创 2019-02-26 18:55:43 · 160 阅读 · 0 评论 -
【STL】06 deque容器
原创 2019-02-26 18:55:39 · 85 阅读 · 0 评论 -
【STL】07 deque容器操作
deque容器的操作基本与vector容器相同,除了少一些方法,比如capacity()#include<iostream>#include<deque>using namespace std;void Print_deque(deque<int>& v){ for(deque<int>::iterator i=v.b...原创 2019-02-26 18:55:50 · 152 阅读 · 0 评论 -
【STL】08 deque选手打分案例
#include<iostream>#include<vector>#include<deque>#include<string>#include<stdlib.h>#include<algorithm>using namespace std;//创建5名选手,每位选手各有10个分数//选手的最终得分为:去...原创 2019-02-26 18:56:08 · 132 阅读 · 0 评论 -
【STL】09 stack容器操作
#include<iostream>#include<stack>using namespace std;void test01(){ stack<int> s1; stack<int> s2(s1); s1.push(1); s1.push(2); s1.push(3); s1.push...原创 2019-02-26 18:56:15 · 119 阅读 · 0 评论 -
【STL】10 queue容器操作
#include<iostream>#include<queue>using namespace std;void test01(){ queue<int> q1; queue<int> q2(q1); q1.push(1); q1.push(2); q1.push(3); q1.push...原创 2019-02-26 18:57:21 · 106 阅读 · 0 评论 -
【STL】11 list容器操作
#include<iostream>#include<list>using namespace std;void test01(){ list<int> mlist1; list<int> mlist2(10,10); //有参构造 list<int> mlist3(mlist2); /...原创 2019-02-26 18:57:14 · 116 阅读 · 0 评论 -
【STL】12 二叉树set容器操作
只能把节点删了再加入新的节点,不能改节点的值#include<iostream>#include<set>using namespace std;//仿函数class mycompare{ public: bool operator()(int v1,int v2){ return v1 &g...原创 2019-02-26 19:00:54 · 308 阅读 · 0 评论 -
【STL】 13 pair 对组
pair对组也可以当成元素放进另一类容器中,例如下面的程序中将pair放进vector容器中#include<iostream>#include<string>#include<vector>using namespace std; void test01(){ pair<int,int> pair1(10,20); ...原创 2019-02-26 18:57:31 · 162 阅读 · 0 评论 -
【STL】14 map容器
#include<iostream>#include<map>using namespace std;//map初始化void test01(){ //map容器模板参数,第一个参数key的类型,第二个参数的类型 map<int,int> mymap; //插入数据 pair.first ...原创 2019-02-26 19:01:17 · 157 阅读 · 0 评论 -
【STL】15 multimap 员工案例
#include<iostream>#include<map>#include<vector>#include<stdlib.h>#include<string>#include<time.h>using namespace std;#define SALE_DEPATMENT 1 // 销售部门...原创 2019-02-26 19:01:00 · 129 阅读 · 0 评论 -
【STL】16 map容器操作补充
#include<iostream>#include<map>using namespace std;class MyKey{ public: int mIndex; int mID; public: MyKey(int index,int id):mIndex(index),mID(id){}};...原创 2019-02-26 19:01:08 · 134 阅读 · 0 评论 -
【STL】 18 容器共性和使用场景
原创 2019-02-26 19:00:42 · 146 阅读 · 0 评论 -
【STL】 19 函数对象(仿函数)基本概念
#include<iostream>#include<vector>#include<algorithm>using namespace std;//函数对象 VS 普通函数struct MyPrint01{ MyPrint01(){ mNum = 0; } void operato...原创 2019-02-26 18:56:52 · 153 阅读 · 0 评论 -
【STL】 20 谓词、内建函数对象
#include<iostream>#include<functional>using namespace std;void test01(){ plus<int> p; cout<<p(1,2)<<endl;}int main(){ test01(); return 0...原创 2019-02-27 19:09:13 · 131 阅读 · 0 评论 -
【STL】 21 函数对象适配器之仿函数适配器 bind1st bind2nd
#include<iostream>#include<vector>#include<functional>#include<algorithm>using namespace std;//预定义函数对象://①仿函数适配器 bind1st bind2ndclass MyPrint01{ //一元函数对象 ...原创 2019-02-27 19:47:41 · 226 阅读 · 1 评论 -
【STL】 22 函数对象适配器之仿函数适配器 not1 not2
#include<iostream>#include<vector>#include<functional>#include<algorithm>using namespace std;//预定义函数对象://②仿函数适配器 not1 not2class MyCompare01{ //二元函数对象(二元谓词:返回值为bo...原创 2019-02-27 20:17:12 · 287 阅读 · 0 评论 -
【STL】 23 函数对象适配器之仿函数适配器 ptr_fun
#include<iostream>#include<vector>#include<functional>#include<algorithm>using namespace std;//预定义函数对象://③仿函数适配器 ptr_funvoid MyPrint01(int v){ cout<<...原创 2019-02-27 20:30:58 · 154 阅读 · 0 评论 -
【STL】 24 函数对象适配器之成员函数适配器 mem_fun mem_fun_ref
#include<iostream>#include<vector>#include<functional>#include<algorithm>using namespace std;//预定义函数对象://④成员函数适配器 mem_fun mem_fun_refclass Person{ public: ...原创 2019-02-27 20:46:28 · 209 阅读 · 0 评论 -
【STL】 25 常用查找的算法
#include<iostream>#include<vector>#include<algorithm>using namespace std;class Person{ public: Person(int id,int age):mId(id),mAge(age){ } //重载 == 符...原创 2019-02-27 21:54:35 · 121 阅读 · 0 评论 -
【STL】 26 常用的遍历算法
#include<iostream>#include<vector>#include<algorithm>using namespace std;//常用的遍历算法: // for_each() 这个都写烂了 - - // transform() 将一个容器中的元素搬运到另一个容器中 struct MyPlus{...原创 2019-02-27 22:13:45 · 112 阅读 · 0 评论 -
【STL】 全排列函数 next_permutation
#include <iostream> #include <algorithm> #include <string>using namespace std;int main(){ char arr01[3]={'a','b','c'}; int arr02[3]={1,2,3}; do { cout<&l...原创 2019-03-18 21:53:59 · 126 阅读 · 0 评论 -
【STL】 找子串出现的次数
目的:找出一个字符串中出现某子串的次数。思路:主要用的是string容器的find方法,find方法主要是找到字符串中出现某子串的位置。例如: s1 = "abcdefgh" s2 = "de" s1.find(s2) = 3但是如果要求出现的子串的次数,则...原创 2019-03-23 21:42:33 · 1255 阅读 · 0 评论