随笔分类 - STL库
摘要:node.h 1 #pragma once 2 //创建模板 3 template <class T> 4 class Node 5 { 6 public: 7 T t;//数据 8 Node *pNext;//指针域 9 }; list.h 1 #pragma once 2 #include "N
阅读全文
摘要:myvector.h 1 #pragma once 2 3 //自己写的vector模板库 4 template <class T> 5 class myvector 6 { 7 public: 8 //构造 9 myvector(); 10 //析构 11 ~myvector(); 12 //尾插
阅读全文
摘要:1 #include 2 #include 3 #include 4 #include 5 using namespace std; 6 7 void test() 8 { 9 shared_ptr P(new int[10]{ 1,2,3,4,5,6,7,8,9,0 }); 10 shared_ptr P1 = P; 11 ...
阅读全文
摘要:1 #include 2 #include 3 #include 4 #include 5 using namespace std; 6 7 //独享内存,其他指针不可以拥有 8 void test1() 9 { 10 //检测到没有调用的话就不分配内存 11 unique_ptr p(new int[10]{ 0 }); 12 //避免指针被...
阅读全文
摘要:1 #include 2 #include 3 #include 4 #include 5 using namespace std; 6 7 struct my 8 { 9 int x; 10 int y; 11 }; 12 13 //智能指针主要用于解决内存泄漏,拥有常规指针一样的使用,重载* ->运算符 14 void run1() 15 { 1...
阅读全文
摘要:如果容器中是类,如果要调用sort则需要重载操作符 "<" 包含头文件 1 #define _CRT_SECURE_NO_WARNINGS 2 #include <vector> 3 #include <list> 4 #include <algorithm> 5 #include <iostrea
阅读全文
摘要:1 #include 2 #include 3 #include 4 #include 5 using namespace std; 6 7 void main() 8 { 9 //拷贝数据,与反向拷贝 10 { 11 vector myint{ 1,2,3,4,5 }; 12 list myli...
阅读全文
摘要:#include <algorithm> 算法 常用版本 描述 返回Type std::find() find(_InIt _Fisrt,_InIt _Last, _Ty& _Val); 从两个迭代器指定的范围中查找指定值 引用被查找的值的iterator或end() std::find_if()
阅读全文
摘要:1 #include 2 #include 3 #include 4 #include 5 using namespace std; 6 7 void main() 8 { 9 vector myint{ 1,2,3,4,5 }; 10 list mylist{ 10,9,7,6,5 }; 11 //copy不能自动拓展,需要被拷贝的有足够的...
阅读全文
摘要:对容器进行填充 1 void show(int x) 2 { 3 cout << x << endl; 4 } 1 int a[10]; 2 //指定一个数据开始,对a进行填充 3 iota(a, a + 10, 1); 4 5 for_each(a, a + 10, show); 容器两个元素进行
阅读全文
摘要:通过仿函数for_each操作 1 vector<int> myv{ 1,2,3,4,5 }; 2 list<double> db{ 1.1,2.2,3.3,4.4,5.5 }; 3 4 //循环算法,算法的泛型 5 print p = for_each(db.begin(), db.end(),
阅读全文
摘要:1 #include 2 #include 3 #include 4 #include 5 #include 6 #include 7 #include 8 #include 9 using namespace std; 10 11 //流迭代器 12 void main1() 13 { 14 //vector v{ 1,2...
阅读全文
摘要:1 #include 2 #include 3 #include 4 using namespace std; 5 6 7 void main() 8 { 9 unordered_multiset myset{ "pig", "pig", "pig" ,"chicken"}; 10 /*for (auto i : myset) 11 { 12 ...
阅读全文
摘要:1 #include 2 //老版本的unordered_map(已经废弃不再使用) 3 #include 4 #include 5 using namespace std; 6 7 8 void main() 9 { 10 //允许重复的映射 11 hash_mapmymap{ { "a1",113 },{ "a2",143 },{ "a3",112...
阅读全文
摘要:1 #include 2 #include 3 //用于计算,计算的性能高于vector与array 4 #include 5 #include 6 using namespace std; 7 8 9 void main() 10 { 11 const double PI = 3.1415926; 12 valarray val(9); 13 ...
阅读全文
摘要:1 #include 2 #include 3 //查询性能最高 4 //允许重复的,hash_map 5 #include 6 #include 7 using namespace std; 8 9 10 void main() 11 { 12 //允许重复的映射 13 unordered_multimapmymap{ {"a1",113},{ "...
阅读全文
摘要:1 #include 2 #include 3 //查询性能最高 4 //增删查改与map是一样的,但是本质区别就是unordered_map底层是hash表,map底层是红黑树 5 #include 6 using namespace std; 7 8 9 void main() 10 { 11 unordered_mapmymap{ {"a1",113},...
阅读全文
摘要:1 #include 2 #include 3 //查询性能最高(不允许重复数据) 4 #include 5 using namespace std; 6 7 8 void main() 9 { 10 unordered_set myset{"move","jump","hello"}; 11 12 //删除hash表第一个 13 //my...
阅读全文
摘要:1 #include 2 #include 3 #include 4 using namespace std; 5 6 7 void main() 8 { 9 multimapmymap; 10 mymap.insert(pair("司令1", 10)); 11 mymap.insert(pair("司令1", 11)); 12 mym...
阅读全文

浙公网安备 33010602011771号