摘要:
常数项时间:以固定的步骤完成一系列操作 基本概念 Vector容器是单向开口的连续内存空间,deque则是一种双向开口的连续线性空间。所谓的双向开口,意思是可以在头尾两端分别做元素的插入和删除操作,当然,vector容器也可以在头尾两端插入元素,但是在其头部操作效率奇差,无法被接受。 Deque容器 阅读全文
posted @ 2021-08-26 16:43
BZ易风
阅读(65)
评论(0)
推荐(0)
摘要:
单端数组 只有一个开口,如vector 双端数组 双向开口 阅读全文
posted @ 2021-08-26 16:37
BZ易风
阅读(43)
评论(0)
推荐(0)
摘要:
迭代器 阅读全文
posted @ 2021-08-26 16:27
BZ易风
阅读(162)
评论(0)
推荐(0)
摘要:
1. //逆时针遍历 void test02() { vector<int>v; for (int i = 0; i < 10; i++) { v.push_back(i); } printVector(v); //逆序迭代器 reverse_iterator for (vector<int>::r 阅读全文
posted @ 2021-08-26 16:15
BZ易风
阅读(244)
评论(0)
推荐(0)
摘要:
存取操作 插入和删除 #define _CRT_SECURE_NO_WARNINGS #include <iostream> using namespace std; #include <vector> /* vector数据存取操作 at(int idx); //返回索引idx所指的数据,如果id 阅读全文
posted @ 2021-08-26 15:47
BZ易风
阅读(41)
评论(0)
推荐(0)
摘要:
1.原理图 实例: #define _CRT_SECURE_NO_WARNINGS #include <iostream> using namespace std; #include <vector> //巧用swap收缩空间 void test01() { vector<int> v; for ( 阅读全文
posted @ 2021-08-26 15:32
BZ易风
阅读(204)
评论(0)
推荐(0)
摘要:
ector容器 单端数组(只有一个开口)、动态数组(动态扩展空间) 构造、赋值、 大小 size 重置大小 resize 容量 capacity 是否为空 empty 交换 swap #define _CRT_SECURE_NO_WARNINGS #include <iostream> using 阅读全文
posted @ 2021-08-26 15:04
BZ易风
阅读(85)
评论(0)
推荐(0)
摘要:
1.vector容器基本概念 vector的数据安排以及操作方式,与array非常相似,两者的唯一差别在于空间的运用的灵活性。Array是静态空间,一旦配置了就不能改变,要换大一点或者小一点的空间,可以,一切琐碎得由自己来,首先配置一块新的空间,然后将旧空间的数据搬往新空间,再释放原来的空间。Vec 阅读全文
posted @ 2021-08-26 14:26
BZ易风
阅读(436)
评论(0)
推荐(0)
摘要:
修改string字符串的内容,下标操作符[]和at都会返回字符的引用。但当字符串的内存被重新分配之后,可能发生错误 #define _CRT_SECURE_NO_WARNINGS #include <iostream> using namespace std; #include <string> v 阅读全文
posted @ 2021-08-26 13:51
BZ易风
阅读(74)
评论(0)
推荐(0)
摘要:
1.直接调用API转换 2.隐式类型转换 #define _CRT_SECURE_NO_WARNINGS #include <iostream> using namespace std; #include <string> /* string和c-style字符串转换 //string 转 char 阅读全文
posted @ 2021-08-26 13:40
BZ易风
阅读(79)
评论(0)
推荐(0)
摘要:
1. /* 插入和删除操作 string& insert(int pos, const char* s); //插入字符串 string& insert(int pos, const string& str); //插入字符串 string& insert(int pos, int n, char 阅读全文
posted @ 2021-08-26 13:24
BZ易风
阅读(166)
评论(0)
推荐(0)
摘要:
字串 #define _CRT_SECURE_NO_WARNINGS #include <iostream> using namespace std; #include <string> /* 字串 string substr(int pos = 0, int n = npos) const;//返 阅读全文
posted @ 2021-08-26 13:20
BZ易风
阅读(28)
评论(0)
推荐(0)
摘要:
比较第一个不相同的字符的大小 #define _CRT_SECURE_NO_WARNINGS #include <iostream> using namespace std; #include <string> /* 比较 compare函数在>时返回 1,<时返回 -1,==时返回 0。 比较区分 阅读全文
posted @ 2021-08-26 11:29
BZ易风
阅读(234)
评论(0)
推荐(0)
摘要:
1.查找和替换 #define _CRT_SECURE_NO_WARNINGS #include <iostream> #include <string> using namespace std; /* 查找和替换 int find(const string& str, int pos = 0) c 阅读全文
posted @ 2021-08-26 11:21
BZ易风
阅读(334)
评论(0)
推荐(0)
摘要:
1.拼接 #define _CRT_SECURE_NO_WARNINGS #include <iostream> using namespace std; #include <string> /* 拼接操作 string& operator+=(const string& str);//重载+=操作 阅读全文
posted @ 2021-08-26 11:04
BZ易风
阅读(276)
评论(0)
推荐(0)
摘要:
存取字符串 char& operator[](int n);//通过[]方式取字符 char& at(int n);//通过at方法获取字符 #define _CRT_SECURE_NO_WARNINGS #include <iostream> using namespace std; #inclu 阅读全文
posted @ 2021-08-26 10:56
BZ易风
阅读(154)
评论(0)
推荐(0)
摘要:
1.构造函数和基本赋值 #define _CRT_SECURE_NO_WARNINGS #include <iostream> using namespace std; #include <string> /* 构造函数 string();//创建一个空的字符串 例如: string str; st 阅读全文
posted @ 2021-08-26 10:32
BZ易风
阅读(151)
评论(0)
推荐(0)
摘要:
基本概念 C风格字符串(以空字符结尾的字符数组)太过复杂难于掌握,不适合大程序的开发,所以C++标准库定义了一种string类,定义在头文件<string>。 String和c风格字符串对比: Char*是一个指针,String是一个类 string封装了char*,管理这个字符串,是一个char* 阅读全文
posted @ 2021-08-26 10:25
BZ易风
阅读(30)
评论(0)
推荐(0)
摘要:
vector STL 中的标准容器之一 :动态数组 #define _CRT_SECURE_NO_WARNINGS #include <iostream> using namespace std; #include <vector> #include <algorithm> void myPrint 阅读全文
posted @ 2021-08-26 10:16
BZ易风
阅读(65)
评论(0)
推荐(0)
摘要:
容器 vector 算法 for_each 头 algorithm 迭代器 iterator 每个容器有专属迭代器 vector<int >v vector<int>::iterator it = ….. v.begin() 指向第一个数据 v.end 指向 最后一个数据的下一个地址 #define 阅读全文
posted @ 2021-08-26 09:30
BZ易风
阅读(202)
评论(0)
推荐(0)
摘要:
1 阅读全文
posted @ 2021-08-26 09:26
BZ易风
阅读(46)
评论(0)
推荐(0)
浙公网安备 33010602011771号