
stl
文章平均质量分 74
chde2Wang
滴水穿石
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
STL-queue.back()队尾误区
queue.back()指向最新插入queue中的值,而非队尾元素,如:queue.pop()多次,并不会影响queue.back()的值。STL 英文back()解释:reference& back();const_reference& back() const;Access last elementReturns a reference to the last element in thequeue. This is the "newest" element in.原创 2021-12-09 21:30:41 · 1193 阅读 · 0 评论 -
STL10-deque容器
deque 双端队列deque 删除操作deque案例:#if 1#include<iostream>#include<deque>using namespace std;void PrintDeque(deque<int>& d) { for (deque<int>::i...原创 2019-07-17 20:34:38 · 119 阅读 · 0 评论 -
STL13-list容器(链表)
链表是由一系列的结点组成,结点包括两个域:一个数据域,一个指针域1、链表内存是非连续的,添加删除元素效率较高,时间复杂度都是常数项,不需要移动元素2、链表只有在需要的时候才会分配内存3、链表只要拿到第一个结点,相当于拿到整个链表。最后一个结点指向为空4、链表需要额外的空间保存结点关系。前驱 后继关系#include<iostream>...原创 2019-07-25 11:02:21 · 184 阅读 · 0 评论 -
C++ 连续输入几个数
#include<iostream>#include<vector>#include<string>using namespace std;int main() { vector<string> v; cout << "please input the count of number:"; int count; cin ...原创 2019-07-22 13:24:57 · 9215 阅读 · 0 评论 -
STL11-stack容器
#if 1#include<iostream>#include<stack>using namespace std;void test01() { //初始化 stack<int> s1; stack<int> s2(s1); //stack操作 s1.push(10); s1.push(20); s1....原创 2019-07-22 14:46:23 · 152 阅读 · 0 评论 -
STL12-queue容器
queue容器 队列容器 先进先出队列只能在一端插入 一端删除队列不能遍历 不提供迭代器 不支持随机访问#if 1#include<iostream>#include<queue>using namespace std;void test01() { queue<int> q; //创建队列 queue<int> q...原创 2019-07-22 15:16:49 · 244 阅读 · 0 评论 -
STL14-set/multiset容器
set只有一个方法就是insert#include<iostream>#include<set>//set和multiset是一个头文件//set内部实现机制 红黑色(平衡二叉树的一种)//关联式容器//set不允许有重复元素//multiset运行有重复元素//容器查找效率高//容器根据元素的值自动对元素排序 默认从小...原创 2019-07-26 14:49:37 · 160 阅读 · 0 评论 -
STL15-map/multimap容器
map的key值不可以重复multimap的key值可以重复#if 1#include<iostream>#include<map>using namespace std;//初始化void test01() { //map容器参数 第一个参数key的类型 第二个参数value类型 map<int, int> my...原创 2019-07-28 16:16:01 · 159 阅读 · 0 评论 -
STL16-容器的使用范围
#define _CRT_SECURE_NO_WARNINGS#include<iostream>#include<vector>using namespace std;#if 0class Person {public: Person(char* name, int age) { this->pName = new char(strlen(n...原创 2019-07-28 16:55:17 · 159 阅读 · 0 评论 -
STL18常用算法
#include<iostream>#include<algorithm>#include<vector>using namespace std;//transform 将一个容器中的元素搬运在另一个容器中#if 0 //错误struct PrintVector { void operator()(int v) { cout <&...原创 2019-07-29 14:43:08 · 147 阅读 · 0 评论 -
STL17-函数对象
仿函数:#include<iostream>#include<vector>#include<algorithm>using namespace std;//仿函数(函数对象)重载“()”操作符 使类对象可以像函数那样调用//仿函数是一个类,不是一个函数//函数对象可以像普通函数一样调用//函数对象可以像普通函数那样接收参数//函数...原创 2019-07-29 13:51:32 · 168 阅读 · 0 评论 -
STL2-类模板
1、类模板实现函数模板在调用时可以自动类型推导类模板必须显式指定类型#include<iostream>using namespace std;template<class T>class Person {public: T mId; T mAge;public: Person(T id,T age){ this->mAge = ag...原创 2019-06-24 18:31:32 · 237 阅读 · 0 评论 -
STL3-MyArray动态数组类模板实现
注意1、右值的拷贝使用2、拷贝构造函数的使用#include<iostream>using namespace std;template<class T>class MyArray{public: MyArray(int capacity) { this->mCapacity = capacity; this->mSize ...原创 2019-07-03 11:04:28 · 479 阅读 · 0 评论 -
STL4-类型转换
#include<iostream>using namespace std;class Building{};clas...原创 2019-07-03 14:09:54 · 467 阅读 · 0 评论 -
STL6-输入输出流
cout 是 console output 缩写程序 和键盘 之间有一个输入缓冲区程序 和 显示器 之间有一个输出缓冲区#include<iostream>#include<windows.h>#include<iomanip>using namespace std;#if 0cout &...原创 2019-07-13 20:30:32 · 314 阅读 · 0 评论 -
STL7-基础
1、容器可以嵌套容器2、容器分为序列式容器和关联式容器序列式容器:容器的元素的位置是由进入容器时机和地点来决定关联式容器:容器已经有规则,进入容器的元素的位置不是由进入容器时机和地点来决定 只与此容器的排列规则有关3、迭代器 理解为指针。实际迭代器是一个类。这个类封装一个指针1、stl算法和数据结构分离#i...原创 2019-07-15 16:23:55 · 152 阅读 · 0 评论 -
STL8-string容器
C 没有 string 类,但提供了直接对字符数组、字符串操作的函数 -> 如 str_len()等等 -> 需要包含 “string.h” #include<iostream>#include<string>using namespace std;//初始化void test01() { string s1; ...原创 2019-07-15 18:45:31 · 168 阅读 · 0 评论 -
STL5-异常
异常可以跨函数异常必须处理1、#include<iostream>using namespace std;//c++异常机制 跨函数//c++异常必须处理 不能留,否则报错int divided(int x, int y){ if (y == 0) throw y; //抛异常 return (x /...原创 2019-07-11 21:58:37 · 171 阅读 · 0 评论 -
STL9-vector容器
vector容器 动态数组 可变数组vector容器 单口容器vector实现动态增长: 当插入新元素时,如果空间不足,那么vector会重新申请更大内存空间(默认二倍),将原空间数据拷贝到新空间,释放旧空间的数据,再把新元素插入新申请空间。当我们知道我们存储的元素大概有多少时,使用reserve方法,减少vector重新申请内存-拷贝数据-释放旧空间的次...原创 2019-07-16 20:02:04 · 167 阅读 · 0 评论 -
STL1-函数模板
1、函数模板和普通函数区别//普通函数可以进行自动类型转换,//函数模板必须精确类型匹配;//函数模板可以被重载;c++优先考虑普通函数;#include<iostream>using namespace std;//函数模板-->产生模板函数-->调用函数template<class T>T MyAdd(T a, T b){ cou...原创 2019-06-23 20:30:01 · 244 阅读 · 0 评论