- 博客(10)
- 收藏
- 关注
原创 c++实现循环链表
cyclelist.h#pragma once#include <iostream>using namespace std;class Node{public: Node() {} Node(int e, Node* p = nullptr) : data(e), next(p) {} ~Node() {}public: int data; Node* ...
2019-04-10 17:11:04
2008
原创 c++实现静态链表
StaticList.h#pragma onceconst int MAXSIZE = 20;class Node{public: long data; int cursor; //指向下一个元素的游标位置};class StaticList{public: StaticList(); ~StaticList(); bool isEmpty(); void ...
2019-04-07 18:57:52
667
原创 c++实现单链表
SingleList.h#pragma onceclass Node {public: Node() {} Node(int info, Node* p) : data(info), next(p) {} ~Node() {} int data; Node* next;};class SingleList{public: SingleList(); ~Sin...
2019-04-03 15:33:01
172
原创 线性表:顺序存储实现
LinearList.h#pragma onceconst int MAXSIZE = 20;typedef int DataType;class DataArr{public: //这里MAXSIZE与length表示不同含义 //MAXSIZE:表示列表的最多可承载的元素个数 //length:表示列表当前的实际元素个数 DataType arr[MAXSIZE];...
2019-03-20 00:11:40
203
翻译 c++标准库笔记:智能指针(4)-- unique_ptr
unique_ptr是一种在异常发生时可帮助避免资源泄露的智能指针。一般而言,unique_ptr可确保一个对象和其相应资源同一时间只被一个pointer拥有。unique_ptr是其所指对象的唯一拥有着,自然而然地,当unique_ptr被销毁,其所指向的对象也就自动销毁。unique_ptr的必要条件就是,它指向的对象只有一个拥有者。使用unique_ptr有个好处就是在函数内部有显...
2019-02-15 13:59:17
291
1
翻译 c++标准库(笔记):智能指针(3) -- shared_ptr使用中可能会出现的问题
问题:int* p = new int;shared_ptr<int> sp1(p);shared_ptr<int> sp2(p); //error上述问题出在sp1和sp2都会在丢失p的拥有权时释放相应资源,也就是会析构两次。基于此,必须保证对象只被一组shared_ptr拥有,应该总是在创建对象和相应资源时直接设立smart pinter:shared_...
2019-02-13 16:37:23
437
翻译 c++标准库(笔记):智能指针(2) -- weak_ptr
shared_ptr主要是为了避免操心指针指向的资源,保证在最后一个对象结束生命的时候其相应资源也被释放,但有些情形并不期望这样或无法运作:1、环式指向:如果两对象使用shared_ptr互相指向对方,而一旦不存在外部引用指向他们时,这种情况下shared_ptr不会释放数据,因为每个对象的use_count()仍是1;#include <iostream>#include &...
2019-02-13 16:35:34
282
原创 c++标准库(笔记):智能指针(1) -- shared_ptr
自c++11起,c++标准库提供了两大类型的智能指针1、shared_ptr2、unique_ptr这两个类被定义在<memory>内shared_ptr:当对象再也不被使用时就被清理创建shared_ptr:shared_ptr<string> pNico(new string("nico"));也可以使用make_shared:shared_ptr<...
2019-02-11 13:29:23
522
原创 c++标准库(笔记):std::tuple
tuple是TR1引入的,它扩展了pair的概念,可以拥有任意数量的元素。tuple的构建与元素访问:tuple<int,float,string> t1(41,6.3,"niconiconi")auto t2 = make_tuple(22,44,"niconiconi");get<0>(t1);get<1>(t1);注1:tuple的元素类型...
2019-02-11 10:20:45
765
原创 c++标准库(笔记):std::pair
std::pair可以将两个value值组成一个单元,经常用于map、multimap、unordered_map、unordered_multimap,以及函数需要返回一对值时使用。std::pair是一个struct而不是一个class,其所有成员均为public:namespece std{ template<typename T1, typename T2> s...
2019-01-17 16:22:35
2566
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人