- 博客(9)
- 收藏
- 关注
原创 AVL平衡二叉搜索树
//简单方法实现AVL的插入#pragma once#include template class AVLTree; template class AVLNode { friend class AVLTree; public: AVLNode():data(Type()),df(0),leftChild(NULL),rightChild(NULL) {} AVLNode(Type t,A
2018-02-06 09:42:47 127
原创 红黑树RBTree
#pragma once //简单方法实现红黑树的插入以及删除(并调整红黑树平衡) template class RBTree; typedef enum{RED=0,BLACK}COLOR; template class RBNode { friend class RBTree; public: RBNode():data(Type()),leftChild(NULL),rightChi
2018-02-06 09:15:12 175
原创 萃取(traits)
#include using namespace std; template struct MyIter { typedef T value_type;//先声明一个内嵌类型 T* ptr; MyIter(T *p):ptr(p) {} T& operator*()const {return *ptr;} }; template typename I::value_type func
2018-01-29 15:50:40 201
原创 STL(queue)
void main() { deque de; for(int i=1; i<512; ++i) { de.push_back(i); } de.push_back(512); de.push_back(513); }//queue.h#ifndef _VECTOR_H #define _VECTOR_H #include"memory.h" template
2018-01-25 17:05:56 170
原创 STL(vector)
简单实现vector void main() { vector v; v.push_back(1); v.push_back(2); v.push_back(3); } //vector.h #ifndef _VECTOR_H #define _VECTOR_H #include"memory.h" template > class vector { public: ty
2018-01-25 16:45:16 136
原创 STL (序列式容器list)
标准模板库 STL(目标:使代码达到通用性) 分为六大部分:空间配置器(申请空间、释放空间、构造对象、析构对象)、迭代器(数据结构相关、算法与容器之间的粘合剂)、算法、容器、仿函数(象函数(使用方法相似)的对象)、容器适配器(将现有的容器进行封装) 下面主要是序列式容器list的简单构架 代码如下: //主函数stlmain.cpp #include #include"list.h"
2018-01-22 18:36:34 266
原创 工厂函数
因为shared_ptr的构造需要new的调用,而用户往往会忽略delete的调用,从而引起重大错误。因此共享指针提供了工厂函数来包装new并消除显式的delete调用。#include#include#includeusing namespace std;using namespace boost;void main(){ shared_ptr ps = make_shared(10);//ne
2018-01-18 19:57:12 294
原创 智能指针shared_ptr
概要:主要解决上一篇的内存泄露以及复制构造函数问题//主函数test如下#includeusing namespace std;//#include#include"shared_ptr.h"void main(){ int *p = new int(10); shared_ptr ps1(p); shared_ptr ps2; ps2 = ps1;//复制拷贝(浅拷贝) cout1
2018-01-18 19:35:39 209
原创 智能指针(auto_ptr,scoped_ptr,shared_ptr)
总结一下今天所学的shared_ptrshared_ptr与scoped_ptr一样包装了new操作符在堆上分配的动态对象,区别在于它是应用技术型的智能指针,可以被自由地拷贝与赋值,在任何地方都可以共享。//主函数test.cpp#includeusing namespace std;//#include#include"shared_ptr.h"void main(){ int *p = new
2018-01-17 20:48:21 226
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人